Open GoogleCodeExporter opened 9 years ago
I can confirm this.
When you use LinkEndChild on a node, it calls LinkEndChild for the TiXmlNode,
which links the two TiXmlNodes together.
When the TiXmlNode is destroyed, it correctly deletes all child TiXmlNodes that
were linked to it, so that's fine.
But there's no reference kept anywhere of the original ticpp::Node, so nothing
ever deletes it.
Original comment by J.R.Hodg...@gmail.com
on 7 Oct 2010 at 9:56
Hello,
i have the same problem as described. My testcode:
pXMLDoc = new Document();
/* create root element */
Element* pDocumentRootElement = new Element("MyRoot");
pXMLDoc->LinkEndChild(pDocumentRootElement);
Element* pMiscellaneous= new Element("MISC");
pDocumentRootElement->LinkEndChild(pMiscellaneous);
pMiscellaneous->LinkEndChild(new Element("tttt", 232)); //not deleted !!!
delete pDocumentRootElement;
delete pXMLDoc;
At the end of this code i have a memory leak. The memory of "...new
Element("tttt", 232)); " is not deleted.
What can I do? Have anyone a solution for this problem ? The documentation of
LinkEnd Child say, that this memory will be deleted after delete of his parent
child.
Original comment by i...@christiansimon.de
on 18 Mar 2011 at 4:51
Hi,
I think this is a more general problem. Reference counters are initialized to 1
via InitRef(), but when you just allocated the object noone points to it and
the counter should be 0.
I use another smart pointer framework (The one in OpenSceneGraph), and counters
are initialized to 0. And of course it works well. I believe the initialization
to 1 is problematic.
Thoughts?
Original comment by sukend...@gmail.com
on 24 Mar 2011 at 11:00
I found this in the documentation...
"There is no reason to create TinyXML++ objects on the heap, using new, because
the memory is managed for you. If you choose to use new to create TinyXML++
objects, you will always need to use delete to clean up."
http://ticpp.googlecode.com/svn/docs/ticpp.html
So maybe that explains the leak, but doesn't this make LinkEndChild() rather
useless? What would be the proper usage for that function?
Original comment by ryan.da...@gmail.com
on 4 Apr 2011 at 3:32
Agreed... LinkEndChild() is supposed to attach a node allocated on user's side,
as far as I know.
Original comment by sukend...@gmail.com
on 11 Apr 2011 at 10:45
Hi,
Did anyone find a resolution to the memory leak issue?
Thanks
Original comment by shomadi...@gmail.com
on 21 Oct 2013 at 10:15
The issue is that ticpp::Element::Element does a 'new' on TiXmlElement, thus
doing 'new' on ticpp::Element is redundant. The effect is as if LinkEndChild
made a copy of the ticpp::Element object.
So where I used to have :
element->LinkEndChild(new ticpp::Element("foo"));
I now have:
ticpp::Element child("foo");
element->LinkEndChild(&child);
Everything works fine and no more leakage. Thanks to ryan (comment #4) for the
document ref.
Original comment by rldu...@gmail.com
on 17 May 2014 at 10:41
Original issue reported on code.google.com by
Mister_H...@hotmail.com
on 5 Mar 2009 at 10:51Attachments: