[jdom-interest] JDOM parser reuse memory problem

Michael Kay mike at saxonica.com
Fri Nov 11 00:33:30 PST 2011

On 10/11/2011 18:51, Rolf Lear wrote:
> Hi Randall, Michael.
> It's an interesting observation... and I can see the implications. I would
> like to take a closer look at at, but that may take a little while.
> I filed https://github.com/hunterhacker/jdom/issues/52
> 'Off the cuff' I can think of one work-around and a few solutions (in
> addition to what Michael has suggested)
> 1. immediately after parsing your real document you then parse a
> dummy/small/inmemory document (even invalid - and catch the exception).
> 2. Currently when you do-no reuse the parser, it goes back to 'first
> principals' and queries JAXP, etc. to find a parser instance Instead it
> could 'cache' the parser 'source' after the first time, and then just
> create a new instance, instead of doing all the class-based lookups...

Ouch. Creating a new parser to parse a small document is a cost that 
it's nice to avoid, but it isn't going to kill you. Going through the 
JAXP factory process to get a new ParserFactory is a monstrous cost that 
can dominate all other processing - and reusing the factory costs nothing.

Michael Kay

More information about the jdom-interest mailing list