Project: Tomcat
Bug 44389 Cleanup of org.apache.naming.resources.CacheEntry resources (memory leak)
Reported: 2008-02-11 02:03:09 | Status: resolved fixed

Hi, I am memory profiling a webapp for my company because we suspect it has memory leaks when redeploying. This webapp has to be redeployed several times a week for security reasons (most of the time it is undeployed) and the memory leaks forced us to shutdown tomcat once a week to avoid OOM exception. I'm using jvm1.5 and tomcat 6.0.13 (also tried with 6.0.14 and today with 6.0.16), and Yourkit as the profiling tool. I have made the test in both linux and windows. I have created a JMeter test to deploy the app using the manager, make some request to the app and then undeploy it using again the manager app in a loop. After some redeployments, I got my OutOfMemoryException. Then I checked with my profiling tool and found that my own classes were correctly destroyed, and the classes retaining more memory were these ones (listed as a heirarchy): org.apache.catalina.core.ApplicationContext$DispatchData org.apache.catalina.core.ApplicationContext mapper of org.apache.catalina.core.StandardContext context of org.apache.tomcat.util.http.mapper.Mapper resources of org.apache.tomcat.util.http.mapper.Mapper$Context cache of org.apache.naming.resources.ProxyDirContext cache of org.apache.naming.resources.ResourceCache org.apache.naming.resources.CacheEntry[] The number of objects of each class were exactly the number of times I had redeployed the webapp. I have checked the contents of CacheEntry inside CacheEntry[] and it has an attribute "name" and the contents are the jsps and tld files of my app. There are as many CacheEntry with the same jsp attribute as times the webapp has been reloaded, so I guess there is no cleaning of CacheEntry resources at context shutdown. To reproduce this, a simple webapp with 2 jsp and a taglibrary can be used. Deploy and undeploy it many times so you can see how the count of these objects grows in memory.

Files changed in fix:
java/org/apache/catalina/core/ApplicationContext.java