How to Handle Out Of Memory - PermGen Space

PermGen memory is the space where the JVM stores the classes and methods data. If you start and stop tomcat a lot in a short time you can also receive this error.

Recommendation

A minimum of 512mb with a recommended setting of 1024mb.

Example

This is an example of the error from the tomcat logs:

javax.servlet.ServletException: java.lang.OutOfMemoryError: PermGen space

    org.apache.jasper.servlet.<wbr/>JspServlet.service(JspServlet.<wbr/>java:268)

    javax.servlet.http.<wbr/>HttpServlet.service(<wbr/>HttpServlet.java:717)

If you have a Windows environment, the easiest way to increas space is to open the tomcat manager either through the executable in the bin directory (tomcat#w.exe - where # is the version) or from the Start menu. Here is a sample:

-XX:MaxPermSize=1024m
-XX:-UseCompressedOops
-XX:+UseConcMarkSweepGC
-XX:+UseParNewGC
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamps

These settings go into the Java Options field on the Java tab. Place them after any settings that already exist.

Note: If the line -XX:MaxPermSize=1024m already exists, increase the amount of memory listed.

If you have a Linux/Unix environment you will set the CATALINA_OPTS in either the startup.sh or reference it from the setenv.sh files.

Here is an example of settings:

CATALINA_OPTS="$CATALINA_OPTS -server -Xms256m -Xmx1024m -XX:PermSize=512m -XX:MaxPermSize=512m"