Memmory Leak Tools

Started by
21 comments, last by Prozak 22 years, 1 month ago
Hmm, I havent used these in a while but I found them like a year, maybe a year and a half ago on flipcode, but I cant find the link to them anymore so here: htt://pigseye.kenesaw.edu/~ncynkus/MMGR.zip

Its a Memory management header and cpp file you include in your program and it gives you a report, credit to: Paul Nettle
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
Advertisement
Do a search for Fortify or LeakTracer.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
Gonna resurrect this useful thread once more to add something:

The FindMemoryLeaks class at the site Magmai pointed out (http://www.kbcafe.com/articles/memory.leaks.html) appeared to work well for several of my applications, but just recently I found it was reporting memory leaks in my app which I was sure was watertight. After doing a bit more investigation, it appeared that it was reporting memory leaks of memory that I never allocated, which I can only assume was allocated by the C runtime library or the C++ standard library, even though they weren''t marked as ''CRT'' memory blocks. This is despite me using the FindMemoryLeaks class as the only static object in my entire program (everything else was a member of or created by the Application class, which was a local to main().) So I took out that class, and replaced it with this in my main.cpp file:
#include <crtdbg.h>#ifdef _DEBUG#define _CRTDBG_MAP_ALLOC#define new new(_NORMAL_BLOCK,__FILE__, __LINE__)#endif...int main(int, char**){    _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );    ... rest of program 

This now proceeded to only report a single memory leak, which was the one I deliberately put into my programs to check that my leak-detection is working

Now, although it might seem arrogant to believe the checking routine that made my code look better, I was sure in this case, after having commented 99% of the code out, that these leaks were something to do with the standard library, and that _CrtSetDbgFlag somehow accounts for this. (The other alternative is that the FindMemoryLeaks class was itself leaking memory, which shouldn''t happen as it allocates nothing.)

So, in summary, I recommend using the _CrtSetDbgFlag function rather than the LeakChecker class. I may be doing something wrong, but it''s usually best to prefer the tool that makes it harder to do something wrong

Oh, and Dark Rain, you need the #define new line in the actual CPP file, as the __FILE__ and __LINE__ macros are resolved relative to the physical file you type them into. It''s tedious to do, but worth it in the end if a correct program is what you''re after.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]

This topic is closed to new replies.

Advertisement