New issue 630 by pas256: Guice + Tomcat potential memory leak
http://code.google.com/p/google-guice/issues/detail?id=630
I have just started using Google Guice with my Tomcat webapp, and have
noticed the following in the catalina.out file whenever the WAR file is
undeployed:
----
May 16, 2011 5:37:24 PM org.apache.catalina.startup.HostConfig
checkResources INFO: Undeploying context [/app]
May 16, 2011 5:37:24 PM org.apache.catalina.loader.WebappClassLoader
clearReferencesThreads SEVERE: A web application appears to have started a
thread named [com.google.inject.internal.util.$Finalizer] but has failed to
stop it. This is very likely to create a memory leak.
May 16, 2011 5:37:24 PM org.apache.catalina.loader.WebappClassLoader
clearThreadLocalMap SEVERE: A web application created a ThreadLocal with
key of type [null] (value
[com.google.inject.internal.InjectorImpl$1@10ace8d]) and a value of type
[java.lang.Object[]] (value [[Ljava.lang.Object;@7e9bed]) but failed to
remove it when the web application was stopped. To prevent a memory leak,
the ThreadLocal has been forcibly removed.
----
I am not sure what causes this, or how I can stop it from happening.
I have only followed the instructions from here:
http://code.google.com/docreader/#p=google-guice&s=google-guice&t=ServletModule
... and haven't done anything fancy with it yet. I just have 2 servlets and
a filter.
This issue is also posted on StackOverflow:
http://stackoverflow.com/questions/6025089/guice-tomcat-potential-memory-leak
See issue 288.
Comment #2 on issue 630 by sberlin: Guice + Tomcat potential memory leak
http://code.google.com/p/google-guice/issues/detail?id=630
(No comment was entered for this change.)
+sberlin, Could you help me understand why this is invalid?
It appears that InjectorImpl creates a ThreadLocal. Could GuiceFilter or
GuiceServletContextListener be used to clean it up?
Yeah, I don't understand what is happening in Issue 288, but I guess it's
related.
I think he meant Duplicate not Invalid.
It was also meant to be fixed in version 2.0... version 3.0 is out and
still not fixed so go figure. Fingers crossed for 3.1
Comment #6 on issue 630 by mccu...@gmail.com: Guice + Tomcat potential
memory leak
http://code.google.com/p/google-guice/issues/detail?id=630
Issue 288 (the background finalizer thread) will be fixed when the Guava
dependency is upgraded to r10+
The ThreadLocal reported by Tomcat is separate - this is actually a simple
Object array of length 1 which is used to manage contexts during injection.
The array element is guaranteed to be null outside of any call to the
injector so it won't cause any leak. The ThreadLocal will be reclaimed
after the injector is no longer referenced. However it may appear to stay
around for longer if you use reflection to peek into the ThreadLocal map
like Tomcat does, due to the current JDK ThreadLocal implementation.
Ah thanks for the details.