OutOfMemory/Heap space errors in Java

Recently I had to work on a Java based rule modeling tool that was built on Java/Eclipse. The tool was pushing both eclipse and the JVM to the limits in terms of memory and I was getting a lot of OutOfMemory exceptions and out of heap space errors, usually these can be fixed by increasing the default limits.

The important settings in question are arguments passed to the JVM on startup, http://java.sun.com/javase/6/docs/technotes/tools/windows/java.html

-Xmsn

Specify the initial size, in bytes, of the memory allocation pool. This value must be a multiple of 1024 greater than 1MB. Append the letter k or K to indicate kilobytes, or m or M to indicate megabytes. The default value is chosen at runtime based on system configuration. For more information, see HotSpot Ergonomics 
Examples:

       -Xms6291456
       -Xms6144k
       -Xms6m
       

-Xmxn

Specify the maximum size, in bytes, of the memory allocation pool. This value must a multiple of 1024 greater than 2MB. Append the letter k or K to indicate kilobytes, or m or M to indicate megabytes. The default value is chosen at runtime based on system configuration. For more information, see HotSpot Ergonomics 
Examples:

       -Xmx83886080
       -Xmx81920k
       -Xmx80m

Other advanced VM settings are documented here, http://java.sun.com/javase/technologies/hotspot/vmoptions.jsp

1.       Eclipse IDE – If the IDE itself is running out of memory when compiling or editing code then you can increase the maximum memory pool using the Xmx option in eclipse.ini file present in the same folder as eclipse.exe.

2.       JVM from within eclipse – If the JVM is running out of memory when running an app from within eclipse, then you can adjust the memory settings from the JVM configuration tab within eclipse.

3.       JVM from Tomcat – On the Apache Tomcat configuration utility on the Java tab, you can specify the memory and heap settings.

Posted via email from Sijin Joseph

2 Comments

 Add your comment
  1. This is one of my major beefs with the JVM… The JVM should just dynamically increase its heap if it is running into too frequent compactions. There’s no reason that end users applications should be allowed to crash because of this.

  2. Default value of -xmx is 64MB.

Leave a Reply