Memmory Leak Tools

Started by
21 comments, last by Prozak 22 years, 1 month ago
What tools can I use to know if my application/ game is leaking memmory? In DOS, I would just do a "mem", run the program then do another "mem". If there was any diference, then I would know that there was a memory leak somewhere. How do I track this problem down in VC++?

[Hugo Ferreira][Positronic Dreams][]
"Research is what I''m doing when I don''t know what I''m doing."
- Wernher Von Braun (1912-1977)

Advertisement

Check out the "_CrtCheckMemory" family of functions. There is sample code, etc.. on MSDN.

-z
The best way i''ve found is to overload the new&delete or alloc and free functions.

Something like this:

#define malloc(size) (mymalloc(size.__FILE__,__LINE__))

then for every alloc put the details into a linked list,
when you free search the list and remove the related memory.

Now at the end of your programm after everything has been released write the contents of the list to a text file, open it and you not only see how much memory you have unreleased but also in what file at what line it was declared.

Checkout flipcode, i think they have a pretty decent tutorial on how to do it, check the articles here on gamedev.net as well.

zipless
/* Ignorance is bliss, then you go and spoil it by learning stuff */
The best tool you can find is Numega Bounds Checker, but its expensive (it''s only downside to me is the price), then there is memprof in the Linux world, dont know if someone has already ported that to Windows.

quote:Original post by zipless
The best way i''ve found is to overload the new&delete or alloc and free functions.

Does that, in your estimation, surpass the CRT family of debug functions declared in <crtdbg.h>?

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!
I seem to remember being able to get the MS CRT functions to tell me when I had memory leaks, but not how I''d allocated those leaks. Therefore I couldn''t find how to fix it. I looked through the docs but didn''t have any luck. Any clues on how to use these functions more effectively?

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
Alternatively you can use a package such as nuMega BoundsChecker which will do extensive leak detection, even on things like GDI resource handles etc.


Kylotan:

http://www.gamedev.net/community/forums/topic.asp?topic_id=71992






--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

I''ve never used crtdbg so i wouldn''t know. I like my overload functions, i can see exactly how much memory i''m using at any time and it has the nice leak detection thing as well.

zipless
/* Ignorance is bliss, then you go and spoil it by learning stuff */
Article on finding Memory Leaks
- 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
Thanks Simon. There is a #define mentioned in MSDN which claims to insert the file/line information, but it simply doesn''t.

This topic is closed to new replies.

Advertisement