You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xerces.apache.org by James Pearson <ji...@banet.net> on 2000/03/01 05:23:57 UTC

The DOM parser and memory management? (NEWBIE)

Hi,

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.

Jim Pearson


RE: The DOM parser and memory management? (NEWBIE)

Posted by James Pearson <ji...@banet.net>.
As it turns out, I found that I wasn't calling delete
after I used DOMString.transcode() - which I was calling
all over the place.

A good lesson.

Jim Pearson


-----Original Message-----
From: Andy Clark [mailto:andyc@apache.org]
Sent: Wednesday, March 01, 2000 9:18 PM
To: xerces-dev@xml.apache.org
Subject: Re: The DOM parser and memory management? (NEWBIE)


James Pearson wrote:
> 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.)

Please pardon a Java guy for butting in here...

I remember Andy Heninger doing a lot of work on the DOM
implementation to make sure that it didn't leak memory.
But... if you're not deleting the DOM_Document object
then you *will* definitely leak.

--
Andy Clark * IBM, JTC - Silicon Valley * andyc@apache.org


Re: The DOM parser and memory management? (NEWBIE)

Posted by Andy Clark <an...@apache.org>.
James Pearson wrote:
> 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.)

Please pardon a Java guy for butting in here...

I remember Andy Heninger doing a lot of work on the DOM 
implementation to make sure that it didn't leak memory.
But... if you're not deleting the DOM_Document object
then you *will* definitely leak.

-- 
Andy Clark * IBM, JTC - Silicon Valley * andyc@apache.org

Re: The DOM parser and memory management? (NEWBIE)

Posted by Andy Clark <an...@apache.org>.
Andy Heninger wrote:
> 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.

Lovely. I'm glad I'm in Java land. ;)

-- 
Andy Clark * IBM, JTC - Silicon Valley * andyc@apache.org

Re: The DOM parser and memory management? (NEWBIE)

Posted by Andy Heninger <he...@us.ibm.com>.
> James Pearson [mailto:jim@banet.net] 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


RE: The DOM parser and memory management? (NEWBIE)

Posted by James Pearson <ji...@banet.net>.
I forgot to say that I'm coding in C++ here.

Thanks again,
Jim


-----Original Message-----
From: James Pearson [mailto:jim@banet.net]
Sent: Tuesday, February 29, 2000 11:24 PM
To: Xerces Dev mailing list (E-mail)
Subject: The DOM parser and memory management? (NEWBIE)


Hi,

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.

Jim Pearson