Hi
I have a ClassLoader leak that looks like it's caused by
com.sun.jersey.spi.inject.Errors. My application is deployed in Tomcat
and Jersey 1.4 is deployed with the application in WEB-INF/lib. [1]
Shows the shortest path to a GC root of a class after undeployment (done
with Eclipse MAT). According to it there's an instance of Errors still
in a ThreadLocal preventing it, it's class and the WebappClassLoader
from becoming eligible for garbage collection.
The first thing I tried was replacing the anonymous TheadLocal in Errors
with a normal TheadLocal (why is #initalValue() synchronized BTW?) and
remove()ing it even if there are no messages (see patch). That however
did not solve the problem.
In the end I wrote a ServletRequestListener that .remove()s
Errors#errors after each request. That fixed the problem. This leads me
to believe that somehow Errors#errors is not cleaned up after each request.
Since my application is fairly simple I was wondering whether other
people how deploy Jersey in Tomcat or Jetty have seen similar issues?
[1]
http://imgur.com/JwjV6.png
Cheers
Philippe