because all the nodes are allocated using new operator. is there an operation to delete a document node and all its child nodes?
search for 'delete' ;)
When anything deriving from TiXmlNode goes out of scope (if on the stack) or is deleted (if on the heap) then the destructor destroys all children:
TiXmlNode::~TiXmlNode() { TiXmlNode* node = firstChild; TiXmlNode* temp = 0;
while ( node ) { temp = node; node = node->next; delete temp; } }
But you can erase everything without waiting for end-of-life with:
void TiXmlNode::Clear() { TiXmlNode* node = firstChild; TiXmlNode* temp = 0;
while ( node ) { temp = node; node = node->next; delete temp; }
firstChild = 0; lastChild = 0; }
Hey Lee - what do you think about changing it so the destructor just calls Clear(), to avoid the code duplication ?
Ellers
Log in to post a comment.
because all the nodes are allocated using new operator.
is there an operation to delete a document node and all its child nodes?
search for 'delete' ;)
When anything deriving from TiXmlNode goes out of scope (if on the stack) or is deleted (if on the heap) then the destructor destroys all children:
TiXmlNode::~TiXmlNode()
{
TiXmlNode* node = firstChild;
TiXmlNode* temp = 0;
while ( node )
{
temp = node;
node = node->next;
delete temp;
}
}
But you can erase everything without waiting for end-of-life with:
void TiXmlNode::Clear()
{
TiXmlNode* node = firstChild;
TiXmlNode* temp = 0;
while ( node )
{
temp = node;
node = node->next;
delete temp;
}
firstChild = 0;
lastChild = 0;
}
Hey Lee - what do you think about changing it so the destructor just calls Clear(), to avoid the code duplication ?
Ellers