Jump to content
  • Advertisement

Archived

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

How to check for memory leaks in C++

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

I have just finished using some dynamic allocation of memory that I am usure of if its correctly deleted? I know the memory is allocated right because my images are displayed correctly. So is their an app that I can run that will tell me I have a memory leak. Thanks

Share this post


Link to post
Share on other sites
Advertisement
Well, you could try including crtdbg.h and then calling _CrtSetDbgFlag( _CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF) at the beginning of the program then run the program in debug mode. It will output to the debug screen when the program ends if you''ve left anything behind. I''m really not sure how reliable it is though

Share this post


Link to post
Share on other sites
You can overload the new and delete operation to keep track a memory allocated. If you want to see a real good memory manager, the Nebula''s one (www.radonlabs.de) is very impressive. If you want something simpler, I can give you mine just contact me

julien.hamaide@multitel.be

Share this post


Link to post
Share on other sites
Paul''s memory manager is great, but unfortunately it has some problems when using STL, so you should not use it, when using some containers from the standard library...
@crazyjul: Where on the radlonlabs page is it? I can''t find any source downloads... Or maybe I''m just blind...

Share this post


Link to post
Share on other sites
Regarding Pauls memory checker. I got an error. Well when I trace through with debugger I use new in a function and call delete in the deconstructor I get an error using his code? So what gives he wants you to call new/delete in the same block of code?? Thanks

Share this post


Link to post
Share on other sites
quote:
Original post by antareus
I use:
_CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_ALWAYS_DF);   


Always worked fine for me.


When I used it I got no reports even if I intentionally left out a delete. I never got any error or statement saying otherwise?

Maybe I am using it wrong? All I should have to do is call _CrtSetDbgFlag() at the beginning of WinMain() right? I am using new and delete, or is this function for malloc and free only? Thanks

[edited by - Mars_999 on September 3, 2003 2:42:40 PM]

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.

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

Sign me up!