Pages

Tuesday, December 31, 2013

Memory leak issue in tomcat [ "java.lang.OutOfMemoryError: PermGen space" error ]

Hi Guys,

While working with tomcat web application server with your J2EE web application, many times you come across the error as follows:

"java.lang.OutOfMemoryError: PermGen space" error

This error is because, the memory/space allocated to your tomcat process is not enough.
You can get rid of this problem by increasing JVM heap size.
To do so, here are the steps:

1. Go to CATALINE_BASE/bin/catalina.sh or CATALINE_BASE/bin/catalina.bat file.
2. make following entry in catalina.sh\catalina.bat file for JAVA_OPTS:

In Windows:

set JAVA_OPTS = -Xms1024m -Xmx10246m -XX:NewSize=256m -XX:MaxNewSize=356m -XX:PermSize=256m -XX:MaxPermSize=356m

In Linux:

export JAVA_OPTS="-Xms1024m -Xmx10246m -XX:NewSize=256m -XX:MaxNewSize=356m -XX:PermSize=256m -XX:MaxPermSize=356m"

You can change the actual heap size and PermGen Space as per your requirement.

Each of the otions are explained below.
•    Server – Run the tomcat in server mode. (the default is developer mode)
•    Xms – Minimum java heap space
•    Xmx – Maximum java heap space. While running on dedicated servers for production instances, keep both these options the same to ensure better utilization of available memory.
•    PermSize – The initial permSize. (default is 64MB)
•    Max PermSize – The maxPermSize. (even here, it may be a good idea to keep the intial and the max value the same).


3. Now, Restart your tomcat.

That's it...!!!
I hope this solutions works for you..
Please let me know, if you are still facing any issue even after following these steps.

Happy Coding...!!!
:)










2 comments: