Jump to content
  • Advertisement


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


detecting memory leaks

This topic is 6030 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!