This topic is now archived and is closed to further replies.


detecting memory leaks

Recommended Posts

To enable memory-checking in VC++ add the following at the start of your main-function:

#ifndef NDEBUG
int flag = _CrtSetDbgFlag (_CRTDBG_REPORT_FLAG);
_CrtSetDbgFlag (flag);

The #ifndef NDEBUG ensures that memory-checking is only enabled when you do debug-runs.
You also need to include the crtdbg.h file.

Unfortunately, with this setup you will only be told the size of the leak and a rather inscrutable hex-code.
You can, however, add the following code to your program (before your functions):

#ifndef NDEBUG
#define new new (_NORMAL_BLOCK, __FILE__, __LINE__)

#define malloc(size) _malloc_dbg(size, _NORMAL_BLOCK, __FILE__, __LINE__)



- Death awaits you all with nasty, big, pointy teeth. -

EDIT: Formatting
EDIT2: Formatting(again)
EDIT3: Formatting (yet again. Goddamn).

[edited by - Neophyte on March 21, 2002 12:43:38 AM]

[edited by - Neophyte on March 21, 2002 12:44:18 AM]

[edited by - Neophyte on March 21, 2002 12:45:24 AM]

Share this post

Link to post
Share on other sites