When this happens, there is usually something in memory that βbindsβ WebappClassLoader (the class loader that is responsible for loading the classes for the instance of your webapp) into memory. If you reload your webapp several times, you can see the number of instances of WebappClassLoader increasing by 1 for each reboot you are doing. This is usually not a leak in Tomcat, but a leak directly in your webapp code, a leak in your library, or a leak caused by several specific Java API calls that do stupid things.
First read the following: http://people.apache.org/~markt/presentations/2010-11-04-Memory-Leaks-60mins.pdf . This is a great description of what exactly is happening.
Secondly, use the profiler to determine what holds references to objects loaded by your WebappClassLoader. Many times, simply using the ServletContextListener, you can clear these links when the webapp stops.
Thirdly, if you find that there is a leak from the library you are using, report it. If you find a leak emanating from a class in the JRE, check out the use cases for JreMemoryLeakPreventionListener: http://tomcat.apache.org/tomcat-6.0-doc/config/listeners.html#JRE_Memory_Leak_Prevention_Listener_-_org.apache.catalemorycoreLeenerener--_org.apache.catalemorycoreLeener_Jorg.apache.catalinacore . If there is no way for what you find, please drop the Tomcat users and let us know what is missing: we will add it.
source share