I am trying to detect memory leak, and I am using make _CRTDBG_MAP_ALLOC macro to locate where the leaks area. So I am defining MACRO like following:
#ifdef _DEB
In my case I ended up including the stuff from this thread into my code. This overrides the new
operator and includes the name of the file and the line number into it for later printing. Not sure if this is applicable to Visual Studio only.
#define _CRTDBG_MAP_ALLOC
#include
#ifdef _DEBUG
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#define new DEBUG_NEW
#endif
The whole test code from the referenced source is:
#define _CRTDBG_MAP_ALLOC
#include
#include
#ifdef _DEBUG
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#define new DEBUG_NEW
#endif
int main()
{
char *a = new char[10];
_CrtDumpMemoryLeaks();
return 0;
}
which in my test case prints:
Detected memory leaks!
Dumping objects ->
e:\test\testapplication\testapplication.cpp(11) : {144} normal block at 0x007F4EF0, 10 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD
Object dump complete.