[jdom-interest] JDOM parser reuse memory problem

Rolf Lear jdom at tuis.net
Thu Nov 17 08:33:40 PST 2011

On 17/11/2011 11:25 AM, BIHANIC Laurent wrote:
> Hi
> Le 17/11/11 17:01, Rolf Lear a écrit :
>> In a more generalized answer, the only issue I can see with having a pool of
>> SAXBuilders is that, if you reuse parsers, you will 'carry' the most recently
>> parsed document from each SAXBuilder until that builder is used again.
> It should not: the reference to the (being) built document is held by
> SAXHander and the reference to SAXHandler (contentHandler) is explicitely set
> to null at the end of the build() method in a finally clause.
> We did this because, in the past, we encountered some JVMs that were reluctant
> to garbage-collect the SAXHandler otherwise.
> Regards,
> Laurent

Hi Laurent.

Yeah, the code in the method indicates that (I was not aware it was you 
who put that in).

There is a bug though, and it could explain some confusion.

The problem is the the XMLReader has had it's various handlers set to 
the SAXHandler (Content, DTD, Error, etc.) and when you re-use the 
XMLReader, you in effect keep a reference to the SAXHandler.

Setting the SAXHandler to null at the end of the build does not cause 
the XMLReader to forget it's handlers.

It is an issue that Randall identified a week or so ago.


More information about the jdom-interest mailing list