Page 1 of 1

Visual Studio Memory Leak Detector

Posted: Sun Jan 06, 2013 8:16 pm
by dandymcgee
Visual Leak Detector
http://vld.codeplex.com/

Literally the easiest thing I've ever used. You reference the lib, include the header and when you exit the application it spits a memory allocation report to the Output window.

When it detects an allocation that was never freed it gives you the call stack at the time of allocation, which includes the file name and line number. For example:
Call Stack:
spritesheet.cpp (29): ProjectGenesis.exe!Spritesheet::Spritesheet + 0x7 bytes
renderengine.cpp (129): ProjectGenesis.exe!RenderEngine::LoadSpritesheetCB + 0x42 bytes
sqlite3.c (90614): ProjectGenesis.exe!sqlite3_exec + 0x15 bytes
renderengine.cpp (143): ProjectGenesis.exe!RenderEngine::LoadSpritesheet + 0x1C bytes
level.cpp (53): ProjectGenesis.exe!Level::Level + 0x12 bytes
gameengine.cpp (189): ProjectGenesis.exe!GameEngine::LoadLevel + 0x2F bytes
main.cpp (83): ProjectGenesis.exe!main + 0x26 bytes
I look at line 29 in Spritesheet.cpp and find:
frameRect = new sf::IntRect();
I add the cleanup code I forgot in Spritesheet::~Spritesheet():
delete frameRect;
No more memory leak.

Re: Visual Studio Memory Leak Detector

Posted: Mon Jan 07, 2013 3:32 pm
by eatcomics
Wow, that is probably one of the coolest things I've ever seen. Thanks.

Re: Visual Studio Memory Leak Detector

Posted: Wed Jan 09, 2013 10:27 am
by MarauderIIC
For those of you on Linux, a popular tool (probably not as easy) is valgrind (val-grihnd, not val-grynd). http://valgrind.org/

Re: Visual Studio Memory Leak Detector

Posted: Wed Jan 09, 2013 12:46 pm
by dandymcgee
MarauderIIC wrote:For those of you on Linux, a popular tool (probably not as easy) is valgrind (val-grihnd, not val-grynd). http://valgrind.org/
I've seen so many people worship that tool, and it's been around for ages. If only someone made something comparable for Windows.