Jump to content
  • Advertisement
Sign in to follow this  
CProgrammer

memory leaks

This topic is 4347 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

In c++ is there any efficient way to find memory leaks in a large project? Perhaps some programm that matches new and deletes? -CProgrammer

Share this post


Link to post
Share on other sites
Advertisement
Another way is to override new and delete. That way you can keep track of everything that is in memory by putting it in a memory manager class. When that class gets destructed at the end of the program, it should be empty. If it's not empty, you can start outputting debug messages or even throw a breakpoint:


#if defined( __WIN32__ ) || defined ( _WIN32 )
# define BreakHere __asm { int 3 }
#else
# define BreakHere asm("break")
#endif

// Call "BreakHere;" to throw a breakpoint. Make sure to only do that in debug mode.




There's lots of stuff on Google about overriding new and delete.

Also, if you're using the GCC compiler, there's already a profile delivered, which also reports memory leaks.

Share this post


Link to post
Share on other sites
Quote:

// Call "BreakHere;" to throw a breakpoint. Make sure to only do that in debug mode.

That's why you should either wrap up your interrupt in "#ifdef _DEBUG" or better yet, use _CrtDbgBreak from the CrtDbg header.

Share this post


Link to post
Share on other sites
Quote:
Original post by raz0r
Quote:

// Call "BreakHere;" to throw a breakpoint. Make sure to only do that in debug mode.

That's why you should either wrap up your interrupt in "#ifdef _DEBUG" or better yet, use _CrtDbgBreak from the CrtDbg header.


Of course, this was just the core of that code :)
Using _CrtDbgBreak is no-go for me, since it only works in Windows and I need stuff to work for Linux and ARM(Nintendo DS) too.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!