You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Eric Cloninger <ec...@collective.ops.palm.com> on 2000/07/28 23:13:31 UTC

RefCount cleanup

I'm using Xerces 1.2.0a and I have the following dilemma

void parse_foo(char *foo)
{
    DOM_Parser parser;
    parser.parse(foo);
    DOM_Document doc = parser.GetDocument();
}

When 'parser' goes out of scope, shouldn't all memory that was allocated as
a result of 'parse()' be freed?  The problem is that most of the DOM_Node's
inside the document have ref counts greater than 1, so when parser goes out
of scope, they are not removed and I get a bunch of leak warnings (using
VC++ 6).

I'm not doing anything to Xerces other than building it.  My actual code is
not much more complex than what I've listed above.  What can I do, within
the framework of Xerces, to force all the nodes to release when I leave
parse_foo()? 

Thanks

-E


Re: RefCount cleanup

Posted by Andy Heninger <an...@jtcsv.com>.
Something out of the ordinary is going on.  In your code,
once both "parser" and "doc" have gone out of scope,
the reference counting should remove all of the nodes
that were in the document.

A bunch of constant strings and a few other assorted objects
will remain.  These are lazily allocated constants that are
reused by all parsers and documents, and will remain until
PlatformUtils::terminate() is called.   You don't normally
need to call this, but it makes leak checking easier if
you do.

So double check that no copies of doc have been left
in statics or have crept out into some other external
context.

Andy Heninger
IBM XML Technology Group, Cupertino, CA
heninger@us.ibm.com



----- Original Message -----
From: "Eric Cloninger" <ec...@collective.ops.palm.com>
To: <xe...@xml.apache.org>
Sent: Friday, July 28, 2000 2:13 PM
Subject: RefCount cleanup


> I'm using Xerces 1.2.0a and I have the following dilemma
>
> void parse_foo(char *foo)
> {
>     DOM_Parser parser;
>     parser.parse(foo);
>     DOM_Document doc = parser.GetDocument();
> }
>
> When 'parser' goes out of scope, shouldn't all memory that was allocated
as
> a result of 'parse()' be freed?  The problem is that most of the
DOM_Node's
> inside the document have ref counts greater than 1, so when parser goes
out
> of scope, they are not removed and I get a bunch of leak warnings (using
> VC++ 6).
>
> I'm not doing anything to Xerces other than building it.  My actual code
is
> not much more complex than what I've listed above.  What can I do,
within
> the framework of Xerces, to force all the nodes to release when I leave
> parse_foo()?
>
>