Click here to Skip to main content
11,477,625 members (76,254 online)
Click here to Skip to main content

Tagged as

Fast and easy memory leak detection

, 27 Jul 2011 CPOL 24.6K 11
Rate this:
Please Sign up or sign in to vote.
An easy way to trap all the memory leaks of your application.
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)

Share

About the Author

Octopod
Web Developer
France France
No Biography provided

Comments and Discussions

 
GeneralReason for my vote of 5 New, handy tool; not extra luxury wh... Pin
YvesDaoust30-Jan-12 21:29
memberYvesDaoust30-Jan-12 21:29 
GeneralReason for my vote of 2 Nice find, but this is crashing for ... Pin
Lakamraju Raghuram26-Jan-12 23:23
memberLakamraju Raghuram26-Jan-12 23:23 
GeneralRe: I think you're facing to the same troubles we can encounter ... Pin
Octopod27-Jan-12 0:13
memberOctopod27-Jan-12 0:13 
I think you're facing to the same troubles we can encounter with VS2008 or other versions. Some applications are more unstable with LiveHeap hooked on them. I'm not sure this is linked to the version of VS.

Maybe you could retry without attaching VS2010 debuggee on your application (Ctrl+F5) ?
GeneralHow does this tool compare with Microsoft's Application Veri... Pin
Paul Heil30-Jun-11 4:21
memberPaul Heil30-Jun-11 4:21 
GeneralRe: LiveHeap gives you a real time view of all your allocations.... Pin
Octopod14-Jul-11 6:52
memberOctopod14-Jul-11 6:52 
GeneralI'm not able to use it means whenever I start debugging a pr... Pin
Member 795561028-Jun-11 3:17
memberMember 795561028-Jun-11 3:17 
GeneralRe: You should then try to put breakpoints to embrace specific f... Pin
Octopod26-Jul-11 23:32
memberOctopod26-Jul-11 23:32 
GeneralReason for my vote of 4 i'll try this one Pin
Don Jomar Hombrebueno27-Jun-11 21:09
memberDon Jomar Hombrebueno27-Jun-11 21:09 
GeneralReason for my vote of 4 Nice one. one of the trick to find ... Pin
jawed.ace22-Jun-11 2:38
memberjawed.ace22-Jun-11 2:38 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150520.1 | Last Updated 27 Jul 2011
Article Copyright 2011 by Octopod
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid