c++ - 使用 TinyXml for C++ 时需要清理哪些内存管理?

标签 c++ memory-management tinyxml

我正在使用 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/

相关文章:

c++ - doxygen defgroup 结果为空组

c - Mem 分配器方法的无效转换 (C)

c++ - 尝试将元素添加到现有节点时程序崩溃

c++ - 删除 vector 中的元素,该元素使用 'new' 运算符分配

c - 动态分配的二维矩阵转置(内存有效)

c++ - 使用 Tinyxml 检查 XML 节点是否存在

c++ - 这是什么 (0x01000000) 以及如何存储它?

python - 无法在共享对象库中插入断点 x,(python 使用来自 c++ 的 .so 库)

c++ - C++11 重载决议的奇怪案例

c++ - 是否保证 std::vector 每个使用分配函数分配的内存也将通过单个解除分配调用立即解除分配?