我正在使用 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?
在我的程序执行结束时,当 doc
超出范围时,是否会清除所有 TiXmlElement*
?我是否需要自己遍历文档树并释放所有内存?
最佳答案
documentation for LinkEndChild
是这样说的:
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.
关于c++ - 使用 TinyXml for C++ 时需要清理哪些内存管理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/853559/