Guice + Tomcat potential memory leak

后端 未结 3 1565
轻奢々
轻奢々 2020-12-17 18:28

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

相关标签:
3条回答
  • 2020-12-17 18:48

    If you are getting this when you shutdown the webapp, I wouldn't worry too much. This type of resource leak on app. shutdown is common. They do become a problem when you frequently do hot deploys (i.e. un-deploy many times without killing the JVM), but they won't be problematic when a cold deploy is done (un-deploy/deploy is done while killing the JVM before re-deploy).

    A common tactic is that you do hot-deploys during development (as they are typically faster than cold-deploys), and only do a cold deploy when the resource leak starts to affect your performance. Then, in production you do a cold deploy on every deploy. Given the number of code/libraries that has this type of leak, trying to eliminate them would be hard IMO.

    0 讨论(0)
  • 2020-12-17 18:49

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

    injector = null;
    System.gc(); 
    

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

    I admit, it looks like I didn't read about bad habit of calling System.gc(), but it totally makes sense, since Guice uses weak references internally.

    P.S. Tomcat 8, Java 8, Guice 3.0

    0 讨论(0)
  • 2020-12-17 19:01

    According to the Guice issue 630 it should be fixed in the next Guice version (as of 11/2011), i.e. when the Guava dependency is upgraded to r10+.

    It seems that the fix is still not in, according to Guice issue 288.

    0 讨论(0)
提交回复
热议问题