Jump to content
  • Advertisement

Archived

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

Ro

Finding Memory Leaks

This topic is 6692 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''m using an MFC program that says my program has a memory leak after I quit the program. It however doesn''t show where the memory leak occured. Is there some way to find the file/line number or object from where the leak occured? I''m using new, new[] and delete, delete []. Thanks for any help!

Share this post


Link to post
Share on other sites
Advertisement
Me guess would be you''re missing a delete

Do you ever re-assign a pointer? You can''t just forget about what it was pointing at... (so long as it''s not null)

Share this post


Link to post
Share on other sites
Look up _CrtDumpMemoryLeaks() in the MSDN docs. You need to #define _CRTDBG_MAP_ALLOC and include stdlib.h and crtdbg.h at the top of the file where you call the memory leak functions. What it does is give you a number for the leak (the allocation number) and you can call _CrtSetBreakAlloc() with that number as a parameter, and it will break your code when it allocates what''s not getting deleted.

I hope this was clear, if not, just look through the MSDN, that should give you all you need.

Share this post


Link to post
Share on other sites
Anyone experienced problems with _CrtDumpMemoryLeaks reporting a whole heap of leaks that aren''t actually leaks. I think (it was a long time ago) it occured when I included iostream.h. Any ideas?

"Paranoia is the belief in a hidden order behind the visible." - Anonymous

Share this post


Link to post
Share on other sites
Yeah, what happens in that case is the cout and cin variables (which are basic_ostream and basic_istream types I think) show up as being in memory at the start, but are not deallocated until after you call _CrtDumpMemoryLeaks at the end of the program. I don''t know, but you might be able to fix that by doing this: There''s a function, _CrtSetDbgFlag I think, that will set CRT debug flags. One of these flags makes it so it dumps the memory leaks on program termination, which will probably be AFTER WinMain returns, and so might fix that problem and not dump the iostream vars. You might try that, although I''m not sure it will work.

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!