hunterhacker/jdom — Issue #52: SAXBuilder not releasing memory after reusing parser
Author: rolfl
Created: 2011-11-10 18:43:11+00:00
State: open

Hi, I'm a performance analyst and found a spot where a product I'm
analyzing is using JDOM. We are creating new SAXBuilders on each thread and
are ending up with a hot lock on the classloader when trying to load up the
XMLReader. I saw that the underlying parser in SAXBuilder can be reused,
thus leading to a proper pooling strategy, but I have a memory concern. In
the case where the parser is reused, nothing is cleared from it at the end
of the build method (so the content handler is still held, which can
reference lots of objects). Since SAXBuilder doesn't expose a way to clear
anything on the reused parser, the only option is using ugly reflection to
clear it, or to use (slightly less ugly) WeakReferences to the SAXBuilders
in my pool so that they evenutally get cleaned up.

Is there a reason that the content handler on 'this.parser' isn't set to
null along with the local content handler being set to null in the finally
block of the build method? If not, I'd suggest this change.