Tuesday, September 2, 2008

PermGen OutOfMemoryError problem in Tomcat

A cause and how to fix java.lang.OutOfMemoryError: PermGen space

The permanent generation is the area of heap that holds all the reflective data of the virtual machine itself, such as class and method objects (also called “method area” in The Java Virtual Machine Specification).

Why do you care?

If an application loads “too many” classes then it is possible it will abort with an OutOfMemoryError. The specific error is: “Exception in thread XXXX java.lang.OutOfMemoryError: PermGen space”

Translation: The JVM itself needs memory to be able to run your application. The PermGen is information about the classes that make up your application. Web applications and Servlet containers often need more PermGen memory than the JVM defaults to be able to run.

Fixing the java.lang.OutOfMemoryError: PermGen space error.

Start your JVM with -XX:MaxPermSize=XXXm where XXX is a number like 128, 256. This will allow the JVM to allocate XXX megabytes of memory for the PermGen space if that space is needed.

How do you find out what’s classes are being stored in PermGen? Trace class loading/unloading


How to trace classes are being loaded or unloaded? Use the command line options -XX:+TraceClassloading and -XX:+TraceClassUnloading http://java.sun.com/docs/hotspot/HotSpotFAQ.html


No comments: