Friday, March 11, 2011

"java.lang.OutOfMemoryError: PermGen space" exception

"java.lang.OutOfMemoryError: PermGen space" exception  
  • Generally seen when redeploying an application on web server.
  • Should not be confused with the heap memory space.
  • Even if you have a lot of heap memory available you may still see these PermGen space errors.
Why?

The JVM has a lot of different memory space/regions. The Heap and PermGen space are two of them.

Heap is used to store objects that are created by your application. Whereas PermGen space is used to load classes. This space has a fixed size which can be changed by using -XX:MaxPermSize in JAVA_OPTS environment variable.

So basically if there is a problem with Garbage collecting routine and it is unable to free up memory that was used for loading classes then gradually the PermGen space will be exhausted and you will then see this error.

To solve this error simply try to increase the PermGen Space. The default value of it in most of the Web Servers is 64MB. Try increasing it to 128 or 256MB.

Here is how the JAVA_OPTS would look like if we want to increase PermGen space to 256.

JAVA_OPTS="-Djava.awt.headless=true -Xms512m -Xmx2048m -XX:MaxPermSize=256m"

No comments:

Post a Comment