You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by Gurkan Erdogdu <gu...@yahoo.com> on 2010/09/27 18:15:48 UTC

ClassLoader Memory Leak

Hello;

I have found that when ejbs are undeployed, some classes holds web application 
classloader and prevents it from GC'ed. I have found that ThreadContext class 
uses ThreadLocal that saves BeanContext instance that contains ModuleContext --> 
AppContext --> ClassLoader. When bean is undeployed via 
Assembler#destroyApplication, BeanContext reference may still be referenced in 
ThreadContext # localStorage and this creates memory leak.

My solution is to add clear(BeanContext) method to ThreadContext and call this 
method from Assembler # destroyApplication via ThreadContext.clear(BeanContext);

clear in ThreadContext
---------------------------------
    public static void clear(BeanContext beanContext){
        ThreadContext threadContext = threadStorage.get();
        if(threadContext != null){
            BeanContext oldContext = threadContext.beanContext;
            if(oldContext != null && 
oldContext.getDeploymentID().equals(beanContext.getDeploymentID())){
                //remove it
                threadStorage.remove();
                threadStorage.set(null);
            }
        }
    }

WDYT?

--Gurkan