Friday, July 2, 2010

Tomcat java.lang.OutOfMemoryError: PermGen space


The "OutOfMemoryError: PermGen space" Java error will appear after Tomcat has exhausted all of its memory. This is typically caused by using the "Update" or "Reload" function on a webapp too many times. Currently, Tomcat and/or the JVM isn't releasing all of the memory when a webapp is destroyed/recreated. After several reloads Tomcat is out of its allotted memory and will hang or freeze.

It is a common error, many people have encountered this problem before you (I guess that's a sad fact). ;-)

The "OutOfMemoryError: PermGen space" message is normally encountered during development activites where a long-running JVM is asked to load/unload builds (i.e. reload/redeploy WARs under Apache Tomcat). However it can also be encountered in a recently spawned JVM under the "right" set of conditions.

The message is a symptom of an incomplete garbage collection sweep where resources are not properly released upon unload/restart.

Solutions

  • Developers: Restart Tomcat after several updates/reloads
  • Developers and Implementers: Allow Tomcat to use more memory. This will not stop the error, just prolong times between tomcat restarts. Follow the 'Java Heap Size' solution instructions.
  • Implementers: Tell Tomcat to not leak memory 
How to Increase Tomcat's Allowed Memory
Start Tomcat with the parameters:
-Xmx512m -Xms512m -XX:PermSize=256m -XX:MaxPermSize=256m -XX:NewSize=128m

Tomcat 6 Developer's GuideInside Eclipse IDE:
  1. Click on Tomcat start up
  2. Click on Java tab in Tomcat startup
  3. Use the parameters above.
To be an expert of Apache Tomcat, I suggest you to read the book Tomcat 6 Developer's Guide.

References:
 
Copyright 2009 Spring vs Java EE Web Dev. Powered by Blogger Blogger Templates create by Deluxe Templates. WP by Masterplan