> James Pearson [mailto:[EMAIL PROTECTED] asks
>
> I'm writing an app that uses the DOM parser in a loop - reading files as
> they become available.
> That is to say, I reuse the parser over and over after instantiating it
only
> once. Is that OK?
>
> I've noticed that memory usage climbs as I keep parsing new input files. I
> had assumed that
> Xerces would auto-magically handle the memory behind the scenes, but now I
> wonder if I
> have to "delete" the DOM_Document after I'm finished with it and before I
> parse a new file.
> (Of course my memory leaks could just be my lousy coding... nah.)
>
> Any help greatly appreciated, naturally.

What you are doing should work without leaking.  We routinely run a
test that does essentially the same thing, parsing documents over
and over, as a leak test.

As Andy Clark noted, you need to make sure that any references (variables
of type DOM_Node, DOM_Document, DOM_Element, etc.) to any
part of the documents that you are finished with are cleared - either
assigned to null, or go out of scope, or are reassigned to refer to
a new document).  So long as any references remain alive, the
DOM document will not be deleted, and the application could presumably
grab the reference, and from there, navigate the entire document.

Explicitly deleting the DOM_Document will lead to big trouble - the
implementation will also delete it, the double-delete will corrupt the
heap, leading to an almost certain crash.

  -- Andy

Reply via email to