Saturday, January 1, 2011

_CrtDumpMemoryLeaks() not working or showing lines

Well, here again trying to figure out why Microsoft doesn't provide a better memory leak tool (grumble grumble) but I am not bitter :)
I was following the instructions on the msdn documentation
http://msdn.microsoft.com/en-us/library/e5ewb1h3(v=vs.80).aspx
But it didn't work for me. It turns out that if you are using a static or dynamic library that is being called then you won't get the lines where the memory leaks happen unless you put the following at the beginning of the library header or where the code of the library you are calling resides.

#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>

Also, some people found these other lines useful as supposed to the lines above

#include <iostream>
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>

#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#define new DEBUG_NEW

You can check this at http://www.gamedev.net/community/forums/topic.asp?topic_id=581580
Good luck fighting these nastier than sin memory leaks.