Visual Studio Memory Leak Detector

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Visual Studio Memory Leak Detector

Post 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.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: Visual Studio Memory Leak Detector

Post by eatcomics »

Wow, that is probably one of the coolest things I've ever seen. Thanks.
Image
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Visual Studio Memory Leak Detector

Post 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/
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Visual Studio Memory Leak Detector

Post 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.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
Post Reply