I have been trying to figure out a memory leak in app-schema (and I think, perhaps even in geoserver in general).
The problem is that the app-schema unit tests run out of memory when they are ran in a batch by maven, never when they are run by themselves. While maven is running the tests, data is accumulated on the heap and at some point it will run out and crash. This is a serious bug.
I have figured out quite a bit about it, using Java Memory Analyzer.
The data that is accumulating is mainly XSD schema information (XSDElementDeclarationImpl etc…).
But no features or types or kept alive.
The other thing I figured out is that the GeoServerImpl , Catalog, ResourcePool, etc… objects are not disposed of. For every test that has been run, these objects are kept on the heap! Although, the abstract test class does get rid of them. My first assumption was that these objects where somehow also keeping XSD information in memory, but I was wrong: it is the other way around.
I have included a screenshot in the attachment that shows the path that keeps the GeoserverImpl alive, through the XSD classes. I have also added a second screenshot of another GeoserverImpl instance’s path ( in the same memory dump). If you look at the addresses you can also see where these paths are the same and where they split up.
XSD schema’s can be imported in to each other, and that is what is going on here.
Here is a summary of my findings
- Almost all XSD classes are singletons, therefore static and kept alive.
- org.geoserver.wfs.xml.v1_1_0.WFS is an exception this rule, it is initiated and contains, indirectly, a link to the running geoserverimpl.
- For every instance of geoserverimpl, a new org.geoserver.wfs.xml.v1_1_0.WFS is created and imported in all the other (static) XSD classes (OGC, GML, etc).
- These imports accumulate - For each test a new import is added.
But what I cannot find, is where and how this org.geoserver.wfs.xml.v1_1_0.WFS is imported in to the other XSD classes. Is there anyone who can point me in the right direction?
Also, even if I do find the place where this happens - the question remains what to do.
- Just try to “undo” the import when closing down geoserver? In that case I definitely need to figure out how the import is happening in the first place.
- Just clear out all of the static XSD classes, and rebuilt them each time.
Regards
(attachments)
···
–
Niels Charlier
Software Engineer
CSIRO Earth Science and Resource Engineering
Phone: +61 8 6436 8914
Australian Resources Research Centre
26 Dick Perry Avenue, Kensington WA 6151