The project needs to use the C + + parsing XML, online search to tinyxml such an open source library, the use of the next Test, the creation of the object after the internal self-contained clear method, but in the loop test (just in C + + do the project soon, there is no special memory leak test tool, So write a dead loop and execute the function function), and use the Task Manager to see that the memory has been increasing ... Later, through debugging, clear will only clear its child nodes, and itself will not be released, so you need to fill up. The code is as follows:
1#include <iostream>2#include"tinyxml.h"3#include"Tinystr.h"4#include <string>5 6 using namespacestd;7 8 9 Ten //Creating an XML file One intCreateXmlFile1 (Const Char*szFileName) A { - intRET =0; - //Create a Document object theTixmldocument *mydocument =Newtixmldocument (); - //create a root element and connect -Tixmlelement *root =NewTixmlelement ("Root"); - +Mydocument->Linkendchild (root); - //creating an in node and linking to root +Tixmlelement *inch=NewTixmlelement ("inch"); A inch->setattribute ("ID",1); atRoot->linkendchild (inch); - // -Tixmlelement *cardid =NewTixmlelement ("Name"); -Cardid->setvalue ("123213"); - inch-Linkendchild (CardID); -Mydocument->SaveFile (szfilename); in -Mydocument->clear ();//just clear the child nodes toDelete myDocument;//Release Yourself + returnret; - } the * voidMain () $ {Panax Notoginseng while(true) - { theCreateXmlFile1 ("File.xml"); + } ASystem"Pause"); the}
Of course, in fact, tinyxml internal is Clearthis method, but there is protected tag, so solve the problem can also call Clearthis method within the clear method, or set Clearthis to public.
Small knowledge accumulation-c++ parsing XML memory leaks using TinyXML