Click here to Skip to main content
Click here to Skip to main content

Fast and easy memory leak detection

By , 27 Jul 2011
 
Here is how we do at work, it's easy, fast and does not imply either code instrumentation nor external library nor complex manipulations. Simply get LiveHeap, a free tool that displays heap's allocations in live.
 
Put a breakpoint at the very start of your program, and another at the very end of it. Run under a debugger to break at first breakpoint, then launch LiveHeap to monitor your process. Do whatever you want to test your application, then quit. On second breakpoint, just see what resides in LiveHeap to get every heap allocation that is still here. Here are your leaks, with their allocation stack traces.
 
That's all! Easy, isn't it?
 
You might have false positive for allocations that are freed by a static var, like singleton (but anyway, having dynamic memory that is uninitialized by the CRT and not you is crappy and you really should avoid doing this).
 
You can also use this technique on a specific method, or simply monitor memory activity of your application with LiveHeap (or any application) to get an accurate understanding of what's happening.
 
Give it a try, you won't regret!
 
Enjoy!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Octopod
Web Developer
France France
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralI'm not able to use it means whenever I start debugging a pr...memberMember 795561028 Jun '11 - 2:17 
I'm not able to use it means whenever I start debugging a process, LiveHelp hangs.
My procedure to use is, put breakpoint at main() function itself or starting brace('{'). then started Livehlp and selected that process but it struck there until i stop the debug process.
 
so I need your kind support here.
 
Thanks.
GeneralRe: You should then try to put breakpoints to embrace specific f...memberOctopod26 Jul '11 - 22:32 
You should then try to put breakpoints to embrace specific functions rather than the all program, and see if it helps. Or you can also, without breakpoints, starting LiveHeap before doing a specific action while your application is already started (like opening a file in your application, then closing it, to get leaks for file opening).

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 27 Jul 2011
Article Copyright 2011 by Octopod
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid