[picocontainer-scm] [jira] Commented: (PICO-373) Logging about memory leaks and ThreadLocals when redeploying a picocontainer-using app on Tomcat 6.0

"Mark J. Sinke (JIRA)" <jira-yCVjj/[email protected]> Mon, 16 Aug 2010 09:32:32 -0500 (CDT)
Newsgroups gmane.comp.java.picocontainer.cvs
Message-ID <6048559.37260.1281969152523.JavaMail.haus-jira@codehaus01.managed.contegix.com>
    [ http://jira.codehaus.org/browse/PICO-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=232128#action_232128 ] 

Mark J. Sinke commented on PICO-373:
------------------------------------

A second source of log pollution is the use of the IntoThreadLocal thread-local. However, since that stores a Class object, it may be a real source of memory leaks. My suggestion is to change DefaultPicoContainer.java as  follows

{{{
330c330
<
---
>
624,628d623
<         synchronized (this) {
<             if (intoThreadLocal == null) {
<                 intoThreadLocal = new IntoThreadLocal();
<             }
<         }
630c625,629
<         return getComponent(componentKeyOrType, (Class<? extends Annotation>) null);
---
>         try {
>             return getComponent(componentKeyOrType, (Class<? extends Annotation>) null);
>         } finally {
>             intoThreadLocal.set(null);
>         }
687,691d685
<                     synchronized (this) {
<                         if (intoThreadLocal == null) {
<                             intoThreadLocal = new IntoThreadLocal();
<                         }
<                     }
}}}

Note that I also removed the lazy initialization of the IntoThreadLocal field, since it is private and initialized on construction (maybe it should be final as well to remove thread-visibility issues).

I added a patch file as well with the same content


> Logging about memory leaks and ThreadLocals when redeploying a picocontainer-using app on Tomcat 6.0
> ----------------------------------------------------------------------------------------------------
>
>                 Key: PICO-373
>                 URL: http://jira.codehaus.org/browse/PICO-373
>             Project: PicoContainer
>          Issue Type: Bug
>          Components: PicoContainer (Java)
>    Affects Versions: 1.3
>         Environment: Linux (Fedora Core 12)
>            Reporter: David North
>            Priority: Minor
>         Attachments: AbstractInjector.patch, DefaultPicoContainer.patch, threadLocalBugDemo.zip
>
>
> Deploy the attached sample application onto Apache Tomcat v6 (included are a pre-built WAR exported from eclipse, a context file for tomcat, and the eclipse project containing the source code).
> Now re-deploy by touching the war file.
> Observe the following line in the catalina.out log file:
> 14-Jul-2010 10:52:02 org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
> SEVERE: A web application created a ThreadLocal with key of type [org.picocontainer.defaults.ConstructorInjectionComponentAdapter$1] (value [org.picocontainer.defaults.ConstructorInjectionComponentAdapter$1@f91da9]) and a value of type [java.lang.Boolean] (value [false]) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.
> Is there some destroy/dispose/shutdown call on picocontainer that I am omitting, or is this a bug?
> The following thread discusses the problem with Tomcat and ThreadLocals and makes a few suggestions for how to avoid it:
> http://echo.nextapp.com/site/node/6254
> I've marked this bug as minor since leaking Booleans isn't a serious memory leak, so it's really just the log spam that's upsetting.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

<hr/>
<p>
To unsubscribe from this list please visit:
</p>
<p>
    <a href="http://xircles.codehaus.org/manage_email">http://xircles.codehaus.org/manage_email</a>