Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What memory management do I need to cleanup when using TinyXml for C++?

I'm doing the following with TinyXml:

TiXmlDocument doc;
TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "", "" );
TiXmlElement* main = new TiXmlElement("main");

TiXmlElement* header = new TiXmlElement("header");
header->SetAttribute("attribute","somevalue");
main->LinkEndChild(header);

// ... Add many more TiXmlElment* to other elements all within "main" element

doc.LinkEndChild(decl);
doc.LinkEndChild(main);

// ... do stuff with doc

// Now I am done with my doc. What memory management happens here? 

At the end of my program's execution, will all of the TiXmlElement* be cleaned up when the doc goes out of scope? Do I need to walk the doc tree and free up all of the memory myself?

like image 851
Alex B Avatar asked May 12 '09 16:05

Alex B


1 Answers

The documentation for LinkEndChild says this:

NOTE: the node to be added is passed by pointer, and will be henceforth owned (and deleted) by tinyXml. This method is efficient and avoids an extra copy, but should be used with care as it uses a different memory model than the other insert functions.

like image 63
Rob Kennedy Avatar answered Nov 11 '22 02:11

Rob Kennedy