Friday 5 August 2011

PermGen - OOME(out of memory error) -Tomcat 7








PermGen  - OOME(out of memory error) -Tomcat 7




PermGen (Permananet Generation) space is the place where JVM stores the classes.Classes are stored in the permgen space using class loaders and unique  class identifiers.Each webapp has its own class loader which allows the use of the different version of classes(with same name) in permgen space with out any conflicts.


So,a webapp has its own class loader and a new class loader is created for every reload.The class loaders are garbage collected by the garbage collector when the application stops.But,in case if some reference still exists even after the application is stopped,the class loaders will not be garbage collected,say you are developing a web app where some reference still exists and on every reload or restart of your server,the permgen is heaping up.
The Permgen space is limited and when the classloaders grow up it results in OOME.To,avoid this we must see that no reference to the webapp remains after the app is stopped.




some sceanrios which can cause Permgen space errors are some references to JDBC driver registration,logging frameworks,threads started but not stopped,non removal of objects in thread locals etc.


Apache Tomcat 7.x has come up with many features,Web application memory leak detection and prevention is one of them.JreMemoryLeakPreventionListener is the new life cycle listener class added that calls the various java apis that are known to retain a reference to the current context class loader.If the webapp is the fist to call such apis then there may result in unnecessary existence of references and hence the unrequired class loaders and so the OOME.If the Tomcat calls the java apis first,the memory leaks can be prevented and hence the JreMemoryLeakPreventionListener.This feature also comes with ability to detect the memory leakage occurence,this is added as enhancement to the WebappClassLoader






These seems to be a good enhancement and we should be seeing less PermGen space error with Tomcat 7.x






Cheers... :-)

1 comment:

  1. Apache Tomcat 5.5 expires on Sept 30, 2012 released on August 31, 2004....

    thanks and advance RIP.... ;-)

    ReplyDelete