Small knowledge accumulation-c++ parsing XML memory leaks using TinyXML

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.