看了使用tinyxml的几个例子,如下void build_simple_doc( )
{
       // Make xml: <?xml ..><Hello>World</Hello>       TiXmlDocument doc;
       TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "", "" );
       TiXmlElement * element = new TiXmlElement( "Hello" );
       TiXmlText * text = new TiXmlText( "World" );
       element->LinkEndChild( text );
       doc.LinkEndChild( decl );
       doc.LinkEndChild( element );
       doc.SaveFile( "madeByHand.xml" );
}发现很多new的都地方没有delete,我大致看了下tinyxml,好像没用智能指针啊,这样会不会内存泄露? 
请用过TinyXML的兄弟解释下

解决方案 »

  1.   

    貌似TiXmlDocument 析构的时候会把每个节点的内存释放掉的。我就是按Tinyxml的例子做的,没内存泄露。
      

  2.   

    不会,TiXmlDocument析构的时候应该会释放这些内存
      

  3.   

    同意1,2楼,TiXmlDocument析构的时候,就会把挂在他上面的所有元素都析构掉。
      

  4.   

    TiXmlDocument doc;
    这个析构会消除所有资源的。 
      

  5.   

    感谢回复,请问这样也没问题吗
    for(int i=0;i<no;i++) {
                TiXmlElement* t_channel=new TiXmlElement("channel");
                t_root->LinkEndChild(t_channel);
                t_channel->SetAttribute("ID",i);
    }
      

  6.   

    没有问题,你只要把指针加到Doc中,它会自动析构的
      

  7.   

    TiXmlDocument会自动释放这些东西,它只是attach了一些指针对象,写程序的时候,很多情况下都会有这样的设计