Hey.
Visual Leak Detector is telling me that I've got memory leaks coming from code that uses ticpp (TinyXML++) code:
void CGE_Level::Write_Tiles(ticpp::Element* root) const
{
using namespace ticpp;
Element* tiles = new Element("tiles");
Element* tile = NULL;
root->LinkEndChild(tiles);
for(const_tile_it it = this->tiles.begin(); it != this->tiles.end(); ++it)
{ // Write each background tile.
tile = new Element("tile");
tile->SetAttribute("type", it->Type());
tile->SetAttribute("pass", it->Passability());
tiles->LinkEndChild(tile);
}
}
void CGE_Level::Write_Portals(ticpp::Element* root) const
{
using namespace ticpp;
Element* portals = new Element("portals");
Element* portal = NULL;
root->LinkEndChild(portals);
for(const_portal_it it = this->portals.begin(); it != this->portals.end(); ++it)
{ // Write each background tile.
portal = new Element("portal");
portal->SetAttribute("to_level", it->To_Level());
portal->SetAttribute("from_x", it->From_Pos().y);
portal->SetAttribute("from_y", it->From_Pos().y);
portal->SetAttribute("to_x", it->To_Pos().x);
portal->SetAttribute("to_y", it->To_Pos().y);
portals->LinkEndChild(portal);
}
}
void CGE_Level::Write(const std::string& file_name) const
{
using namespace ticpp;
Document xml_doc(file_name);
Declaration* dec = new Declaration(DEF_VER, DEF_ENC, DEF_STA);
xml_doc.LinkEndChild(dec);
Element* root = new Element("level");
xml_doc.LinkEndChild(root);
root->SetAttribute("width", size.x);
root->SetAttribute("height", size.y);
Write_Tiles(root);
Write_Portals(root);
xml_doc.SaveFile(file_name);
}
Quote:WARNING: Visual Leak Detector detected memory leaks!
---------- Block 4309 at 0x0051CC78: 8 bytes ----------
Call Stack:
c:\tinyxml++\ticpp.cpp (1089): TiCppRC::TiCppRC
c:\tinyxml++\tinyxml.h (217): TiXmlBase::TiXmlBase
c:\tinyxml++\tinyxml.cpp (136): TiXmlNode::TiXmlNode
c:\tinyxml++\tinyxml.cpp (508): TiXmlElement::TiXmlElement
c:\tinyxml++\ticpp.cpp (874): ticpp::Element::Element
c:\documents and settings\bill\my documents\visual studio 2005\projects\console_game_engine\console_game_engine\cge_level.cpp (103): CGE_Level::Write_Portals
c:\documents and settings\bill\my documents\visual studio 2005\projects\console_game_engine\console_game_engine\cge_level.cpp (135): CGE_Level::Write
c:\documents and settings\bill\my documents\visual studio 2005\projects\console_level_editor\console_level_editor\cge_editor.cpp (145): CGE_Editor::Save
c:\documents and settings\bill\my documents\visual studio 2005\projects\console_level_editor\console_level_editor\cge_editor.cpp (56): CGE_Editor::Update_And_Draw
c:\documents and settings\bill\my documents\visual studio 2005\projects\console_level_editor\console_level_editor\cge_editor.cpp (46): CGE_Editor::Run
c:\documents and settings\bill\my documents\visual studio 2005\projects\console_level_editor\console_level_editor\main.cpp (72): main
f:\rtm\vctools\crt_bld\self_x86\crt\src\crtexe.c (586): __tmainCRTStartup
f:\rtm\vctools\crt_bld\self_x86\crt\src\crtexe.c (403): mainCRTStartup
0x7C817067 (File and line number not available): RegisterWaitForInputIdle
Data:
01 00 00 00 00 00 00 00 ........ ........
---------- Block 4307 at 0x0051CB20: 12 bytes ----------
Call Stack:
c:\documents and settings\bill\my documents\visual studio 2005\projects\console_game_engine\console_game_engine\cge_level.cpp (103): CGE_Level::Write_Portals
c:\documents and settings\bill\my documents\visual studio 2005\projects\console_game_engine\console_game_engine\cge_level.cpp (135): CGE_Level::Write
c:\documents and settings\bill\my documents\visual studio 2005\projects\console_level_editor\console_level_editor\cge_editor.cpp (145): CGE_Editor::Save
c:\documents and settings\bill\my documents\visual studio 2005\projects\console_level_editor\console_level_editor\cge_editor.cpp (56): CGE_Editor::Update_And_Draw
c:\documents and settings\bill\my documents\visual studio 2005\projects\console_level_editor\console_level_editor\cge_editor.cpp (46): CGE_Editor::Run
c:\documents and settings\bill\my documents\visual studio 2005\projects\console_level_editor\console_level_editor\main.cpp (72): main
f:\rtm\vctools\crt_bld\self_x86\crt\src\crtexe.c (586): __tmainCRTStartup
f:\rtm\vctools\crt_bld\self_x86\crt\src\crtexe.c (403): mainCRTStartup
0x7C817067 (File and line number not available): RegisterWaitForInputIdle
Data:
0C B0 4C 00 78 CC 51 00 68 CB 51 00 ..L.x.Q. h.Q.....
---------- Block 4291 at 0x0051C820: 8 bytes ----------
Call Stack:
c:\tinyxml++\ticpp.cpp (1089): TiCppRC::TiCppRC
c:\tinyxml++\tinyxml.h (217): TiXmlBase::TiXmlBase
c:\tinyxml++\tinyxml.cpp (136): TiXmlNode::TiXmlNode
c:\tinyxml++\tinyxml.cpp (508): TiXmlElement::TiXmlElement
c:\tinyxml++\ticpp.cpp (874): ticpp::Element::Element
c:\documents and settings\bill\my documents\visual studio 2005\projects\console_game_engine\console_game_engine\cge_level.cpp (92): CGE_Level::Write_Tiles
c:\documents and settings\bill\my documents\visual studio 2005\projects\console_game_engine\console_game_engine\cge_level.cpp (133): CGE_Level::Write
c:\documents and settings\bill\my documents\visual studio 2005\projects\console_level_editor\console_level_editor\cge_editor.cpp (145): CGE_Editor::Save
c:\documents and settings\bill\my documents\visual studio 2005\projects\console_level_editor\console_level_editor\cge_editor.cpp (56): CGE_Editor::Update_And_Draw
c:\documents and settings\bill\my documents\visual studio 2005\projects\console_level_editor\console_level_editor\cge_editor.cpp (46): CGE_Editor::Run
c:\documents and settings\bill\my documents\visual studio 2005\projects\console_level_editor\console_level_editor\main.cpp (72): main
f:\rtm\vctools\crt_bld\self_x86\crt\src\crtexe.c (586): __tmainCRTStartup
f:\rtm\vctools\crt_bld\self_x86\crt\src\crtexe.c (403): mainCRTStartup
0x7C817067 (File and line number not available): RegisterWaitForInputIdle
Data:
01 00 00 00 00 00 00 00 ........ ........
ETC...
In total there are 208!
I didn't delete the pointers I created here because I followed the
tutorial and they didn't use delete. I read somewhere that TinyXML++ handles the memory internally... but when I saw vld reporting the memory leaks, I realised I had stuffed up and that I hadn't actually deleted the pointers... pretty stupid I know.
So two questions:
1) What does TinyXML++ do in terms of handling new'd memory?
2) Why would they not delete the pointers in their tutorials?
Cheers!