Finding Memory Leaks

Started by
9 comments, last by Facehat 24 years ago
I''ve heard of some programs which can find memory leaks C++ code. Does anyone have any reccomendations about which one of these I should get? And what sort of price can I expect to pay? --TheGoop
Advertisement
Boehm''s Garbage collection library is avaliable from Xerox for free, and can perform leak detection as well as garbage collection. (Because, after all, every time you need to collect the garbage, you''ve got a leak. )
Sounds pretty good . But what part of the site is that on? (I used the search utility, but I was unable to find it)

--TheGoop
Yeah, I looked for the thing on www.xerox.com for it too, but couldn''t find it...
Here''s a Xerox ftp directory: ftp://parcftp.xerox.com/pub/gc/

But aparantly since the last time I checked, Boehm had moved from Xerox to SGI to HP. Here''s the HP link, I didn''t check if the library was actually more recent than the Xerox Parc link.

http://www.hpl.hp.com/personal/Hans_Boehm/gc/
If you run in debug mode, you can just use the _Crt functions to detect any over/undrwrite, memoryleaks and other useful information from the debug heap. Easy to use, for example run _CrtDumpMemoryLeaks() at the end of your program.

/ LC
-------------------------------------------------------------LGPL 3D engine - http://www.sourceforge.net/projects/realityengine
I read in VC++ Developers Journal a while ago that _CrtDumpMemoryLeaks will give incorrect results if you include header files that declare objects, such as iostream.h (declared cout, cin, etc..). It said that it will return the size of those objects, because their destructors haven''t been run yet. It this true?
Yea you can use the _Crt functions. Try lookin up _CrtSetDbgFlag. int _CrtSetDbgFlag( int newFlag );

here''s a snippet out of MSDN
1. Call _CrtSetDbgFlag with newFlag equal to _CRTDBG_REPORT_FLAG to obtain the current _crtDbgFlag state and store the returned value in a temporary variable.

2.Turn on any bits by OR-ing the temporary variable with the corresponding bitmasks (represented in the application code by manifest constants).

3.Turn off the other bits by AND-ing the variable with a bitwise NOT of the appropriate bitmasks.

4.Call _CrtSetDbgFlag with newFlag equal to the value stored in the temporary variable to set the new state for _crtDbgFlag.

and a flag of interest for detecting memory leaks upon exit is _CRTDBG_LEAK_CHECK_DF.
This will basically call the _CrtDumpMemoryLeaks() upon exit in debug mode. Hope this helps ya out.
Of course that''s assuming you''re using Visual C++.
Qoy - I had those problems..So I would say it''s true. I logged it to the hd and got a 81k file with all the leaks in my application. Think I had any? Nah.

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

This topic is closed to new replies.

Advertisement