Heap Size - Errors, Meanings and Key Variables*
Assuming the following
Trouble Shooting guide for Java heap errors
Invalid maximum heap size: -Xmx0.9g
Could not create the Java virtual machine.
The correct command should be java -Xmx928m BigApp
Key Variables
* All matter is compiled from various sources on the Internet.
- Java program being run
- Program being run from Command line
- Program name = BigApp.class
Trouble Shooting guide for Java heap errors
- Missing m, M, g or G at the end (they are case insensitive). For example
java -Xmx128 BigApp
java.lang.OutOfMemoryError: Java heap space
The correct command should be: java -Xmx128m BigApp. To be precise, -Xmx128 is a valid setting for very small apps, like HelloWorld. But in real life, I guess you really mean -Xmx128m - Extra space in JVM options, or incorrectly use =. For example
java -Xmx 128m BigApp
Invalid maximum heap size: -Xmx
Could not create the Java virtual machine.
java -Xmx=512m HelloWorld
Invalid maximum heap size: -Xmx=512m
Could not create the Java virtual machine.
The correct command should be java -Xmx128m BigApp, with no whitespace nor =. -X options are different than -Dkey=value system properties, where = is used. - Only setting -Xms JVM option and its value is greater than the default maximum heap size, which is 64m. The default minimum heap size seems to be 0. For example
java -Xms128m BigApp
Error occurred during initialization of VM
Incompatible initial and maximum heap sizes specified
The correct command should be java -Xms128m -Xmx128m BigApp. It’s a good idea to set the minimum and maximum heap size to the same value. In any case, don’t let the minimum heap size exceed the maximum heap size. - Heap size is larger than your computer’s physical memory. For example
java -Xmx2g BigApp
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.
The fix is to make it lower than the physical memory: java -Xmx1g BigApp - Incorrectly use mb as the unit, where m or M should be used instead
java -Xms256mb -Xmx256mb BigApp
Invalid initial heap size: -Xms256mb
Could not create the Java virtual machine. - The heap size is larger than JVM thinks you would ever need. For example
java -Xmx256g BigApp
Invalid maximum heap size: -Xmx256g
The specified size exceeds the maximum representable size.
Could not create the Java virtual machine.
The fix is to lower it to a reasonable value: java -Xmx256m BigApp - The value is not expressed in whole number. For example
Invalid maximum heap size: -Xmx0.9g
Could not create the Java virtual machine.
The correct command should be java -Xmx928m BigApp
Key Variables
- Tomcat Server - CATALINA_OPTS, JAVA_OPTS (preferably CATALINA_OPTS so other Java applications hosted on same server are not impacted). Example - CATALINA_OPTS=”-Xms512m -Xmx512m” (Windows). Make sure server is stopped and started for these settings to take effect.
- JBoss Server - $JBOSS_HOME/bin/run.conf and edit JAVA_OPTS. Example - JAVA_OPTS=”-server -Xms128m -Xmx128m". Make sure server is stopped and started for these settings to take effect.
- Glassfish Application Server - edit $GLASSFISH_HOME/domains/domain1/config/domain.xml, search for XML element name java-config and jvm-options. For example
<java-config suffix=”…”>
<jvm-options>-Xmx512m</jvm-options>
<jvm-options>-XX:NewRatio=2</jvm-options>
<jvm-options>-XX:MaxPermSize=128m</jvm-options>
…</java-config> - Eclipse IDE - Edit eclipse-home/eclipse.ini to be something like the following and restart Eclipse
-vmargs
-Xms64m
-Xmx256m - Netbeans IDE - Edit netbeans-install/etc/netbeans.conf to be something like netbeans_default_options=”-J-Xms512m -J-Xmx512m -J-XX:PermSize=32m -J-XX:MaxPermSize=128m -J-Xverify:none and restart Netbeans
- Apache ANT - Set environment variable ANT_OPTS. For example - ANT_OPTS=”-Xms512m -Xmx512m” (Windows)
- JEdit Editor - jEdit is a java application, and basically you need to set minimum/maximum heap size JVM options when you run java command. jEdit by default runs with a default maximum heap size 64m.
If using desktop icon, change shortcut properties from C:\jdk6\bin\javaw.exe -jar “C:\jedit\jedit.jar” to C:\jdk6\bin\javaw.exe -Xmx128m -Xms128m -jar “C:\jedit\jedit.jar"
If usinga java command or a script, then use command including min and max heap size as - java -Xmx128m -Xms128m -jar jedit.jar
* All matter is compiled from various sources on the Internet.
Maintained By - Ankur Gupta