New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak in com.sun.xml.bind.v2.ClassFactory #831
Comments
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented If it's possible to reproduce this - please create some testCase and we'll try to fix it. |
@glassfishrobot Commented The problem is compounded in a Tomcat environment because you have no idea which thread will run your request, and you also get one instance of the cache for every thread which happens to use JaxB. It is possible to clean up after use by calling ClassFactory.clearCache(), either after you're done unmarshalling the XML or in a ServletRequestListener after your servlet is done. The problem is of course that this reduces the advantage of having a cache in the first place. One fix might be to just change it to a static map instead of a ThreadLocal map, class definitions aren't exactly likely to change depending on the executing thread. |
@glassfishrobot Commented 30-Apr-2013 15:25:01.677 SEVERE [tomcat-http--3] org.apache.catalina.loader.WebappClassLoader.checkThreadLocalMapForLeaks The web application created a ThreadLocal with key of type [com.sun.xml.bind.v2.ClassFactory$1] (value [com.sun.xml.bind.v2.ClassFactory$1@13c27c22]) and a value of type [java.util.WeakHashMap] (value [ {class javax.xml.bind.annotation.W3CDomHandler=java.lang.ref.WeakReference@4563a650} ]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. Any advice is appreciated. |
@glassfishrobot Commented |
|
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 [
{class javax.xml.bind.annotation.W3CDomHandler=java.lang.ref.WeakReference@5af92541}
]) 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 #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.
Affected Versions
[2.2.2]
The text was updated successfully, but these errors were encountered: