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 Fran Orzel <fm...@us.ibm.com> on 2009/06/23 20:01:35 UTC

Question on when to release a node

Hi,

I have code that is generating and XML Document using the C++ DOM 
Parser/Serializer.  In my code I create a node via the 
DOMDocument->createElement() call.  I manipulate this node as needed 
(setting attributes, adding children, etc...) and then append it to a 
parent node.  All of this code is being done in a loop that runs for a 
varying number of times. 

Do I need to release the node after I append it to the parent each time 
through the loop?   Right now I simply relese the entire document after I 
write it out to a file......  Or do I need to do something like save the 
nodes in an array and then walk the array after all have been processed to 
append each one to the document to make sure I am not overlaying the node 
address each time through the loop ?? 

I am asking this because I am getting some memory errors when my loop ends 
and I think it is because the memory associated with the nodes is 
"invalid" or someting;

Fran 

Re: Question on when to release a node

Posted by David Bertoni <db...@apache.org>.
Fran Orzel wrote:
> 
> Hi,
> 
> I have code that is generating and XML Document using the C++ DOM 
> Parser/Serializer.  In my code I create a node via the 
> DOMDocument->createElement() call.  I manipulate this node as needed 
> (setting attributes, adding children, etc...) and then append it to a 
> parent node.  All of this code is being done in a loop that runs for a 
> varying number of times.  
> 
> Do I need to release the node after I append it to the parent each time 
> through the loop?   Right now I simply relese the entire document after 
> I write it out to a file......  Or do I need to do something like save 
> the nodes in an array and then walk the array after all have been 
> processed to append each one to the document to make sure I am not 
> overlaying the node address each time through the loop ??  
Once you've added the node to the document, it's owned by the document, 
and you shouldn't release it. Also, once you release a document, even 
nodes that were never added to the document will be released.

> 
> I am asking this because I am getting some memory errors when my loop 
> ends and I think it is because the memory associated with the nodes is 
> "invalid" or someting;
The current DOM implementation allocates nodes from a large block of 
memory, so it's unlikely that memory for the nodes is no longer allocated.

Perhaps if you give more details of your platform, and the kinds of 
errors you're seeing, someone may be able to help.

Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org