I get the following error message from Tomcat on redeploying my webapp:
02.05.2011 18:26:13 org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
SCHWERWIEGEND: The web application [/foo] created a ThreadLocal with key of type [com.sun.xml.bind.v2.ClassFactory$1] (value [com.sun.xml.bind.v2.ClassFactory$1@54b8cdc]) and a value of type [java.util.WeakHashMap] (value [
]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
I.e. Tomcat tries to clean up after the applications deployed on it, but the problem is really in the application and not in Tomcat. My application creates a JAXBContext on startup. JAXBContext has no destroy() method, so I'd expect is to do its own cleanup.
This is really a duplicate of
JAXB-563, but I do not have the permission to reopen that bug.
Reviewing the source code of com.sun.xml.bind.v2.ClassFactory, it is easy to see that this class creates a static private ThreadLocal storage and never calls remove() on the ThreadLocal, so this is clearly the root cause of the problem.