Potential memory leak Guice + Tomcat

I just started using Google Guice with my Tomcat webapp and noticed that in the catalina.out file all WAR files are unallocated:

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.

Does anyone know what causes this, or how can I stop it?

I just followed the instructions from here http://code.google.com/docreader/#p=google-guice&s=google-guice&t=ServletModule

... and havenโ€™t come up with anything yet. I have only 2 servlets and a filter.

Thank!

+12
java tomcat guice guice-servlet
May 17 '11 at
source share
3 answers

If you get this when you turn off webapp, I would not worry too much. This type of resource leak is in the application. shutdown is common. They become a problem when you often do hot deployments (i.e., Do not deploy many times without killing the JVM), but they will not be problematic when performing a cold deployment (deployment / deployment is performed during the kill of the JVM before redeploying).

The general tactic is that you perform a hot deployment during development (usually faster than a cold deployment), and only a cold deployment when a resource leak begins to affect your performance. Then in production, you perform a cold deployment with each deployment. Given the number of codes / libraries that have this type of leak, trying to fix them will be a difficult IMO.

+4
May 17 '11 at 1:24
source share

According to problem 630 , it should be fixed in the next version of Guice (starting from 11/2011), that is, when the Guava dependency is updated to r10 +.

The fix seems to be still not in line with issue 288 .

+5
Dec 20 '11 at 10:08
source share

This helped me get rid of the "SEVERE" journal entry for com.google.inject.internal.InjectorImpl :

 injector = null; System.gc(); 

If the injector was the result of Guice.createInjector(...modules...)

I admit that I have not read about the bad habit of calling System.gc () , but this is perfectly reasonable, as Guice uses weak links inside.

PS Tomcat 8, Java 8, Guice 3.0

0
Jun 25 '15 at 21:38
source share



All Articles