How to deal with “java.lang.OutOfMemoryError: Java heap space” error?

后端 未结 21 1664
死守一世寂寞
死守一世寂寞 2020-11-21 04:49

I am writing a client-side Swing application (graphical font designer) on Java 5. Recently, I am running into java.lang.OutOfMemoryEr

相关标签:
21条回答
  • 2020-11-21 05:07

    Yes, with -Xmx you can configure more memory for your JVM. To be sure that you don't leak or waste memory. Take a heap dump and use the Eclipse Memory Analyzer to analyze your memory consumption.

    0 讨论(0)
  • 2020-11-21 05:07

    Follow below steps:

    1. Open catalina.sh from tomcat/bin.

    2. Change JAVA_OPTS to

      JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms1536m 
      -Xmx1536m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m 
      -XX:MaxPermSize=256m -XX:+DisableExplicitGC"
      
    3. Restart your tomcat

    0 讨论(0)
  • 2020-11-21 05:12

    I have faced same problem from java heap size.

    I have two solutions if you are using java 5(1.5).

    1. just install jdk1.6 and go to the preferences of eclipse and set the jre path of jav1 1.6 as you have installed.

    2. Check your VM argument and let it be whatever it is. just add one line below of all the arguments present in VM arguments as -Xms512m -Xmx512m -XX:MaxPermSize=...m(192m).

    I think it will work...

    0 讨论(0)
  • 2020-11-21 05:13

    I read somewhere else that you can try - catch java.lang.OutOfMemoryError and on the catch block, you can free all resources that you know might use a lot of memory, close connections and so forth, then do a System.gc() then re-try whatever you were going to do.

    Another way is this although, i don't know whether this would work, but I am currently testing whether it will work on my application.

    The Idea is to do Garbage collection by calling System.gc() which is known to increase free memory. You can keep checking this after a memory gobbling code executes.

    //Mimimum acceptable free memory you think your app needs
    long minRunningMemory = (1024*1024);
    
    Runtime runtime = Runtime.getRuntime();
    
    if(runtime.freeMemory()<minRunningMemory)
     System.gc();
    
    0 讨论(0)
  • 2020-11-21 05:14

    You could specify per project how much heap space your project wants

    Following is for Eclipse Helios/Juno/Kepler:

    Right mouse click on

     Run As - Run Configuration - Arguments - Vm Arguments, 
    

    then add this

    -Xmx2048m
    
    0 讨论(0)
  • 2020-11-21 05:16

    if you got this error when you launch eclipse birt 1- you will go in the file of the eclipse configuration 2- you must open eclipse.init 3- modified the RAM memory, you can increase this, i give an example.

    my old information was : -Xmx128m -XX:MaxPermSize=128m

    the new modification that i opered :

    -Xmx512m -XX:MaxPermSize=512m

    this modification will permit me to resolve java heap space when i launch my report in my browser.

    Thanks

    0 讨论(0)
提交回复
热议问题