Hi guys,
We are most struggling with “Out of memory error” in web application when reference memory is over head.
For example:
public final class Large {
private static final double[ ] [ ] [ ] matrix = new double [1357] [ 1687] [4];
public static final void main(String[] arg) {
}
}
O/P:
java.lang.OutOfMemoryError: Java heap space
at outofmemory.Large.<clinit>(Large.java:5)
Exception in thread “main”
How to solve?
Increase java heap space based on jvm which you used.
Set java heap size in JVM?
java -Xms64m -Xmx512m
where -Xms<size> specifies the initial Java heap size and -Xmx<size> the maximum Java heap size.
Set java heap size in Tomcat?
Stop Tomcat server, set environment variable CATALINA_OPTS
, and then restart Tomcat. Look at the file tomcat-install/bin/catalina.sh
or catalina.bat
for how this variable is used. For example,
set CATALINA_OPTS="-Xms512m -Xmx512m" (Windows)
export CATALINA_OPTS="-Xms512m -Xmx512m" (ksh/bash)
setenv CATALINA_OPTS "-Xms512m -Xmx512m" (tcsh/csh)
Set java heap size in JBoss?
Stop JBoss server, edit $JBOSS_HOME/bin/run.conf
, and then restart JBoss server. You can change the line with JAVA_OPTS
to something like:
JAVA_OPTS="-server -Xms128m -Xmx128m"
Set java heap size in Eclipse?
You have 2 options:
1. Edit eclipse-home/eclipse.ini to be something like the following and restart Eclipse.
-vmargs
-Xms64m
-Xmx256m
2. Or, you can just run eclipse command with additional options at the very end. Anything after -vmargs will be treated as JVM options and passed directly to the JVM. JVM options specified in the command line this way will always override those in eclipse.ini. For example,
eclipse -vmargs -Xms64m -Xmx256m
Set java heap size in Weblogic?
Java heap size values must be specified whenever you start WebLogic Server. This can be done either from the Java command line or by modifying the default values in the sample startup scripts that are provided with the WebLogic distribution for starting WebLogic Server.
For example, when starting WebLogic Server from a Java command line, the heap size values could be specified as follows:
$ java -XX:NewSize=128m -XX:MaxNewSize=128m -XX:SurvivorRatio=8 -Xms512m -Xmx512m
-Dweblogic.Name=%SERVER_NAME% -Dbea.home=”C:\bea”
-Dweblogic.management.username=%WLS_USER%
-Dweblogic.management.password=%WLS_PW%
-Dweblogic.management.server=%ADMIN_URL%
-Dweblogic.ProductionModeEnabled=%STARTMODE%
-Djava.security.policy=”%WL_HOME%\server\lib\weblogic.policy”
weblogic.Server
The default size for these values is measured in bytes. Append the letter `k’ or `K’ to the value to indicate kilobytes, `m’ or `M’ to indicate megabytes, and `g’ or `G’ to indicate gigabytes.
For more information on the heap size options
Setting the New generation heap size -XX:NewSize
Setting the maximum New generation heap size -XX:MaxNewSize
Setting New heap size ratios -XX:SurvivorRatio
Setting minimum heap size -Xms
Setting maximum heap size -Xmx
I found your site on technorati and read a few of your other posts. Keep up the good work. I just added your RSS feed to my Google News Reader. Looking forward to reading more from you down the road!
Your blog is interesting!
Keep up the good work!
Excellent. Thanks
The eclipse.ini changes them for eclipse itself(which may or may not need to be bigger than tomcat) but if you want to change the values that tomcat uses you will need to go to window->preferences->java-installed jre’s->edit and add them to the ‘Default VM Arguments’ box.
I set them both and that seemed to do the trick.
Cheers!
Can you please tell me how to make that configuration in UNIX server. I am struggling to increase the Java Heap space but don’t know where to find the line where i could include this configuration.
Any help will be highly appreciated.
the explanation is really good.
Thanks alot.
nice and good
I am facing java heap space error while trying to delete my project resources in eclipse,My current heap size in eclipse.ini :
xms: 40m
xmx: 512m.
can you please suggest the initial and maximum heap values i can set to increase the heap space.
I have 4 GB RAM machine
According to my experience This looks mainly due to small size of permanent generation of heap.just increase size by using JVM option -XX:MaxPermSize=256m” as shown here
This weblog is good. There is generally all of the appropriate information at the ideas of my fingers. Thanks and maintain up the excellent work!
Oh thanks this interesting keep it up
This is a topic that is close to my heart… Thank you!
Where are your contact details though?