java.lang.OutOfMemoryError: Java heap space


Problem:

The error ‘java.lang.OutOfMemoryError: Java heap space’ is caused when the JVM (Java Virtual Machine) runs out of available memory during processing. This can be caused by:

  • a large number of files on your system
  • an extremely large benchmark document
  • memory leak with some apis / user defined classes

The default heap memory in JVM sets a maximum heap size of 64MB. The directions below describe how to increase this value on UNIX and Windows systems.

Solution:

For UNIX systems, edit the catalina.sh file under tomcat_home/bin and set JAVA_OPTS as below

JAVA_OPTS="$JAVA_OPTS "-Xms512m" "-Xmx1024m".

Where ‘-Xmx1024m’ sets the maximum heap size to 1024MB of memory. Higher values may be used where additional memory is available.

For Windows systems, edit catalina.bat, change the text -Xmx256m to a larger value. For example:

JAVA_OPTS="$JAVA_OPTS "-Xms512m" "-Xmx1024m"

Where "-Xmx1024m" sets the maximum heap size to 1024MB of memory. Higher values may be used where additional memory is available.

Memory Problems With Mysql Connector

GOOD:
mysql.jar (221 kb, 10/7/2003)
mysql-connector-java-3.0.16-ga-bin.jar (231 kb, 11/16/2004)
mysql-connector-java-3.0.17-ga-bin.jar (241 kb, 6/22/2005)
BAD (memory leak):
mysql-connector-java-3.1.10-bin.jar (409 kb, 6/23/2005)
mysql-connector-java-3.1.14-bin.jar (449 kb, 10/18/2006)
… (other versions)
mysql-connector-java-5.1.6-bin.jar (687 KB, 3/5/2008)

Related Posts:

3 Responses


java.lang.OutOfMemoryError: Java heap space | Internet Directory January 10, 2008 at 2:15 pm

[…] These icons link to social bookmarking sites where readers can share and […]


Samrat January 10, 2008 at 2:15 pm

Hi Laxman,

I have set -Xmx1024m at the run.conf of the JBOSS. Instead of that, I am getting this error, “java.lang.OutOfMemoryError”. The machine has 2GB of RAM. Do you know the reason ?

Thanks
Samrat


javatechie January 10, 2008 at 2:15 pm

Hi Samrat,

Check below link, may be helpful for u.

http://blog.yannis-lionis.gr/?p=8


Comments are closed.