6

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:

enter image description here

But I still get the same error. Am I missing something?

Community
  • 1
  • 1
Rikkin
  • 509
  • 1
  • 5
  • 20
  • 1
    This answer may help in running your specific class:
    [http://stackoverflow.com/a/8601040/288387][1] [1]: http://stackoverflow.com/a/8601040/288387
    – elsadek Nov 25 '14 at 16:51
  • 1. 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](http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html#DebuggingOptions) 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. –  Nov 25 '14 at 17:13
  • Oh, 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. –  Nov 25 '14 at 17:16
  • Finally, the assumption is that this program throws an OOM if run standalone, and not via Eclipse. You should prove this assumption is correct. –  Nov 25 '14 at 17:21

4 Answers4

3

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/

elsadek
  • 1,028
  • 12
  • 39
  • Good point that I missed. This error is happening when the class is *run* not during ordinary IDE operations. Good catch. –  Nov 25 '14 at 16:55
2

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.

1

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

Sharif
  • 1,488
  • 17
  • 21
0

Assuming you have 4gb or more RAM, try something like this in eclipse.ini(notice the capital/small letter "m"):

--launcher.XXMaxPermSize
1024M
--launcher.XXMaxPermSize
1024m
-vmargs
-Xms512m
-Xmx2048m
gromm
  • 16