Skip to main content
gamedev.net
🔒 Locked

Finding Memory Leaks

Started by Ro 3 replies 400+ views
Original Post
Ro
Ro
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!
Shannon Barber
Shannon Barber
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)
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Qoy
Qoy
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.
Staffan
Staffan
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
Qoy
Qoy
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.