[jdom-interest] JDOM parser reuse memory problem

Rolf Lear jdom at tuis.net
Fri Nov 11 03:21:53 PST 2011


On 11/11/2011 3:33 AM, Michael Kay wrote:
> 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
> Saxonica
>
Not sure what you are saying... are you agreeing that the 'ouch' problem 
is the one it has at the moment, or the suggestion to skip the JAXB 
processing on subsequent non-reuse-parser parses?

I have not yet had a close look at the problem... the potential option 
of not going back to first-principles on subsequent parses may not be 
(easily) possible.... Unless Randall can convince me otherwise, I'm 
going to finish working on some StAX outputter code I am embroiled in, 
and then look at it.

Rolf


More information about the jdom-interest mailing list