Can't solve "Java heap space" error in eclipse
Solution 1
Where is the "vmargs" option? If you set the min/max heap, you probably need to do it on the main process, not the launcher.
See the Eclipse FAQ item on setting VM options.
That launcher PermSize opt is a bit ridiculous. Unless you know it is launcher PermSize causing the OOM, keep it at the default of 256m.
[EDIT]
As pointed out else-thread, if this is happening when you run your Java program from Eclipse, you tweak those settings within the "Run Configuration" for that program, not Eclipse.ini.
Also, remember that you can tweak the VM options all you want, but if the program wants to eat all the resources on the box before it OOMs, no amount of tweaking can mitigate this.
Solution 2
The memory settings in eclipse.ini is allocated to Eclipse IDE only, not the program you want to run. A very common mistake is updated the heap size in eclipse.ini, and expects it to solve above out of memory problem.
http://www.mkyong.com/eclipse/eclipse-java-lang-outofmemoryerror-java-heap-space/
Solution 3
If we are using windows try this:
Try setting a Windows System Environment variable called _JAVA_OPTIONS with the heap size you want. Java should be able to find it and act accordingly
Below settings workes for me : -Xms512m -Xmx1024m -XX:MaxPermSize=512m
Rikkin
Updated on July 25, 2022Comments
-
Rikkin almost 2 years
While running my Java code in Eclipse IDE, I got the error:
Exception in thread "D3D Screen Updater" Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
I searched for this error and tried solutions described here and here, but they did not work.
I changed these parameters in eclipse.ini:
--launcher.XXMaxPermSize
512M
-Xms40m
-Xmx512m
to:
--launcher.XXMaxPermSize
1024M
-Xms512m
-Xmx2048m
EDIT:
I changed this parameters at Run Configurations:
But I still get the same error. Am I missing something?
-
elsadek over 9 yearsThis answer may help in running your specific class:<br/> [stackoverflow.com/a/8601040/288387][1] [1]: stackoverflow.com/a/8601040/288387
-
Admin over 9 years1. I'd put those two opts on separate lines 2. I guess the program is blowing something out. It could be heap, or it could be something else. You could enable verbose GC logging and/or run the program in debug mode from Eclipse. If the problem takes some time to fail, you can attach a profiler to it, like VisualVM or jconsole (found in the JDK bin directory). Finally, you can config the VM to dump heap on OOMs.
-
Admin over 9 yearsOh, I guess we should ask: did you roll back those Eclipse.ini changes you made? Because those resources are shared, and, especially on Windows, you are going to get resource contention fast if Eclipse is grabbing all the PermGen or whatever.
-
Admin over 9 yearsFinally, the assumption is that this program throws an OOM if run standalone, and not via Eclipse. You should prove this assumption is correct.
-
-
Admin over 9 yearsGood point that I missed. This error is happening when the class is run not during ordinary IDE operations. Good catch.