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