Affects Version/s: 1.11
Platform: GlassFish 22.214.171.124/126.96.36.199
OS: Any OS
Jersey: 1.11.1 --> 1.17 (tested)
Deploying the simplest Jersey app, running to initialize to get a JAXB
XML resource and undeploying it. Repeating this for a long time
it is seen that GlassFish 3.1.x WebappClassLoader leaks and
eventually gets OutOfMemoryError in PermGen space.
The testcase is just a simple annotated Jersey Demarshaller to XML. (on GFv312 tip)
and whatever Jersey 1.17 (used – including newest Jersey)
It seems that when the JAXBContext is created it is kept in
by the call com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.getStoredJAXBContext
The jaxbContexts is a WeakHashMap keyed on a "Instance Object" (referrent) created
on the WebappClassLoader and the value is the JAXBContextImpl
It seems to be that the problem in theory with a WeakHashMap if the "Instance Object"
has not strong reference the JAXBContextImpl will automatically be GC.
But this is not the case since JAXBContextImpl itself holds the "Instance Object"
within a collection. This implicitly make this object have a strong reference
from JAXBContextImpl. Due to this the WebappClassLoader is not removed
after a deploy/run/undeploy test.
By the way, if bundling Jersey inside the webappp & setting GlassFish
delegate=false classloader option, there is no leak (since the jersey is
local and hence impervious to the issue).