You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ibatis.apache.org by "Sylvain Laurent (JIRA)" <ib...@incubator.apache.org> on 2008/10/03 10:16:44 UTC

[jira] Created: (IBATIS-540) Classloader memory leak because of ThreadLocal in ResultObjectFactoryUtil

Classloader memory leak because of ThreadLocal in ResultObjectFactoryUtil
-------------------------------------------------------------------------

                 Key: IBATIS-540
                 URL: https://issues.apache.org/jira/browse/IBATIS-540
             Project: iBatis for Java
          Issue Type: Bug
          Components: SQL Maps
    Affects Versions: 2.3.3, 2.3.4
            Reporter: Sylvain Laurent
         Attachments: ibatis patch for classloader memleak.txt

I'm using iBatis in a webapp with Spring and facing memory leaks upon redeployment oft he webapp.
I tracked the leaks to ibatis, where the class ResultObjectFactoryUtil has a static ThreadLocal factorySettings

The problem is that the value bound to a Thread through this ThreadLocal is never nullified, and since the "factorySettings" is a static variable, the ThreadLocal instance is reachable as long as the ClassLoader of the webapp is reachable. But since the FactorySettings instance is bound to the Thread through a strong reference (see the JDK implementation of ThreadLocal in ThreadLocalMap$Entry), the classloader is finally never collected...

The solution is to always cleanup the ThreadLocal after usage (in SqlExecurtor)
I attach a patch for iBatis 2.3.4 to this issue

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Re: [jira] Commented: (IBATIS-540) Classloader memory leak because of ThreadLocal in ResultObjectFactoryUtil

Posted by Jeff Butler <je...@gmail.com>.
+1.  I'll do it.

Jeff Butler


On Fri, Oct 3, 2008 at 8:52 AM, Kai Grabfelder (JIRA)
<ib...@incubator.apache.org> wrote:
>
>    [ https://issues.apache.org/jira/browse/IBATIS-540?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12636636#action_12636636 ]
>
> Kai Grabfelder commented on IBATIS-540:
> ---------------------------------------
>
> cool, then I guess it is save to apply it ;-). @Devs? What do you think?
>
>> Classloader memory leak because of ThreadLocal in ResultObjectFactoryUtil
>> -------------------------------------------------------------------------
>>
>>                 Key: IBATIS-540
>>                 URL: https://issues.apache.org/jira/browse/IBATIS-540
>>             Project: iBatis for Java
>>          Issue Type: Bug
>>          Components: SQL Maps
>>    Affects Versions: 2.3.3, 2.3.4
>>            Reporter: Sylvain Laurent
>>         Attachments: ibatis patch for classloader memleak.txt
>>
>>
>> I'm using iBatis in a webapp with Spring and facing memory leaks upon redeployment oft he webapp.
>> I tracked the leaks to ibatis, where the class ResultObjectFactoryUtil has a static ThreadLocal factorySettings
>> The problem is that the value bound to a Thread through this ThreadLocal is never nullified, and since the "factorySettings" is a static variable, the ThreadLocal instance is reachable as long as the ClassLoader of the webapp is reachable. But since the FactorySettings instance is bound to the Thread through a strong reference (see the JDK implementation of ThreadLocal in ThreadLocalMap$Entry), the classloader is finally never collected...
>> The solution is to always cleanup the ThreadLocal after usage (in SqlExecurtor)
>> I attach a patch for iBatis 2.3.4 to this issue
>
> --
> This message is automatically generated by JIRA.
> -
> You can reply to this email to add a comment to the issue online.
>
>

[jira] Commented: (IBATIS-540) Classloader memory leak because of ThreadLocal in ResultObjectFactoryUtil

Posted by "Kai Grabfelder (JIRA)" <ib...@incubator.apache.org>.
    [ https://issues.apache.org/jira/browse/IBATIS-540?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12636636#action_12636636 ] 

Kai Grabfelder commented on IBATIS-540:
---------------------------------------

cool, then I guess it is save to apply it ;-). @Devs? What do you think?

> Classloader memory leak because of ThreadLocal in ResultObjectFactoryUtil
> -------------------------------------------------------------------------
>
>                 Key: IBATIS-540
>                 URL: https://issues.apache.org/jira/browse/IBATIS-540
>             Project: iBatis for Java
>          Issue Type: Bug
>          Components: SQL Maps
>    Affects Versions: 2.3.3, 2.3.4
>            Reporter: Sylvain Laurent
>         Attachments: ibatis patch for classloader memleak.txt
>
>
> I'm using iBatis in a webapp with Spring and facing memory leaks upon redeployment oft he webapp.
> I tracked the leaks to ibatis, where the class ResultObjectFactoryUtil has a static ThreadLocal factorySettings
> The problem is that the value bound to a Thread through this ThreadLocal is never nullified, and since the "factorySettings" is a static variable, the ThreadLocal instance is reachable as long as the ClassLoader of the webapp is reachable. But since the FactorySettings instance is bound to the Thread through a strong reference (see the JDK implementation of ThreadLocal in ThreadLocalMap$Entry), the classloader is finally never collected...
> The solution is to always cleanup the ThreadLocal after usage (in SqlExecurtor)
> I attach a patch for iBatis 2.3.4 to this issue

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (IBATIS-540) Classloader memory leak because of ThreadLocal in ResultObjectFactoryUtil

Posted by "Jeff Butler (JIRA)" <ib...@incubator.apache.org>.
     [ https://issues.apache.org/jira/browse/IBATIS-540?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jeff Butler closed IBATIS-540.
------------------------------

    Resolution: Fixed

Fixed in SVN.

It was a bit more difficult than the patch suggested - because SqlExecuter can be called recursively if there are nested sub-selects in result maps.  So I changed ResultObjectFactoryUtil to implement a Stack rather than a single instance of the configuration.  This will also make the calls to the ResultObjectFactory more accurate - because the statement id's will be correct in all cases (even if the call is a result of a nested sub select).

I believe the issue is fixed, but if you find more issues feel free to reopen.
 

> Classloader memory leak because of ThreadLocal in ResultObjectFactoryUtil
> -------------------------------------------------------------------------
>
>                 Key: IBATIS-540
>                 URL: https://issues.apache.org/jira/browse/IBATIS-540
>             Project: iBatis for Java
>          Issue Type: Bug
>          Components: SQL Maps
>    Affects Versions: 2.3.3, 2.3.4
>            Reporter: Sylvain Laurent
>            Assignee: Jeff Butler
>         Attachments: ibatis patch for classloader memleak.txt
>
>
> I'm using iBatis in a webapp with Spring and facing memory leaks upon redeployment oft he webapp.
> I tracked the leaks to ibatis, where the class ResultObjectFactoryUtil has a static ThreadLocal factorySettings
> The problem is that the value bound to a Thread through this ThreadLocal is never nullified, and since the "factorySettings" is a static variable, the ThreadLocal instance is reachable as long as the ClassLoader of the webapp is reachable. But since the FactorySettings instance is bound to the Thread through a strong reference (see the JDK implementation of ThreadLocal in ThreadLocalMap$Entry), the classloader is finally never collected...
> The solution is to always cleanup the ThreadLocal after usage (in SqlExecurtor)
> I attach a patch for iBatis 2.3.4 to this issue

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (IBATIS-540) Classloader memory leak because of ThreadLocal in ResultObjectFactoryUtil

Posted by "Sylvain Laurent (JIRA)" <ib...@incubator.apache.org>.
    [ https://issues.apache.org/jira/browse/IBATIS-540?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12636625#action_12636625 ] 

Sylvain Laurent commented on IBATIS-540:
----------------------------------------

According to the comments in the original class, it was a way of passing around some data without changing the prototypes of many methods.
There's no performance impact, anyway the ThreadLocal is setup before each call. My patch just clean it up after the call

> Classloader memory leak because of ThreadLocal in ResultObjectFactoryUtil
> -------------------------------------------------------------------------
>
>                 Key: IBATIS-540
>                 URL: https://issues.apache.org/jira/browse/IBATIS-540
>             Project: iBatis for Java
>          Issue Type: Bug
>          Components: SQL Maps
>    Affects Versions: 2.3.3, 2.3.4
>            Reporter: Sylvain Laurent
>         Attachments: ibatis patch for classloader memleak.txt
>
>
> I'm using iBatis in a webapp with Spring and facing memory leaks upon redeployment oft he webapp.
> I tracked the leaks to ibatis, where the class ResultObjectFactoryUtil has a static ThreadLocal factorySettings
> The problem is that the value bound to a Thread through this ThreadLocal is never nullified, and since the "factorySettings" is a static variable, the ThreadLocal instance is reachable as long as the ClassLoader of the webapp is reachable. But since the FactorySettings instance is bound to the Thread through a strong reference (see the JDK implementation of ThreadLocal in ThreadLocalMap$Entry), the classloader is finally never collected...
> The solution is to always cleanup the ThreadLocal after usage (in SqlExecurtor)
> I attach a patch for iBatis 2.3.4 to this issue

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (IBATIS-540) Classloader memory leak because of ThreadLocal in ResultObjectFactoryUtil

Posted by "Kai Grabfelder (JIRA)" <ib...@incubator.apache.org>.
    [ https://issues.apache.org/jira/browse/IBATIS-540?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12636605#action_12636605 ] 

Kai Grabfelder commented on IBATIS-540:
---------------------------------------

doesn't this has a performance impact? What's the point of using the ThreadLocal if it is cleaned just right after it has been set?

> Classloader memory leak because of ThreadLocal in ResultObjectFactoryUtil
> -------------------------------------------------------------------------
>
>                 Key: IBATIS-540
>                 URL: https://issues.apache.org/jira/browse/IBATIS-540
>             Project: iBatis for Java
>          Issue Type: Bug
>          Components: SQL Maps
>    Affects Versions: 2.3.3, 2.3.4
>            Reporter: Sylvain Laurent
>         Attachments: ibatis patch for classloader memleak.txt
>
>
> I'm using iBatis in a webapp with Spring and facing memory leaks upon redeployment oft he webapp.
> I tracked the leaks to ibatis, where the class ResultObjectFactoryUtil has a static ThreadLocal factorySettings
> The problem is that the value bound to a Thread through this ThreadLocal is never nullified, and since the "factorySettings" is a static variable, the ThreadLocal instance is reachable as long as the ClassLoader of the webapp is reachable. But since the FactorySettings instance is bound to the Thread through a strong reference (see the JDK implementation of ThreadLocal in ThreadLocalMap$Entry), the classloader is finally never collected...
> The solution is to always cleanup the ThreadLocal after usage (in SqlExecurtor)
> I attach a patch for iBatis 2.3.4 to this issue

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.