Click here to Skip to main content
15,891,033 members
Articles / General Programming / Debugging
Alternative
Tip/Trick

Fast and easy memory leak detection

Rate me:
Please Sign up or sign in to vote.
2.67/5 (3 votes)
26 Jan 2012CPOL 15.6K   1   6
For Visual Studio IDE we can detect leaks by using CRT debugger functions#define _CRTDBG_MAP_ALLOC#include #include void main(){ // ...... // ...... _CrtDumpMemoryLeaks();}This will dump leaks if any to the Output window. Check this link :...
For Visual Studio IDE we can detect leaks by using CRT debugger functions

C++
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>

void main()
{
   // ...... 
  // ......

  _CrtDumpMemoryLeaks();
}</crtdbg.h></stdlib.h>


This will dump leaks if any to the Output window. Check this link : http://msdn.microsoft.com/en-us/library/e5ewb1h3(v=vs.80).aspx[^]

Any way this seems to a nice tool. I will try it for sure. My 5

License

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


Written By
Technical Lead
India India
_____________________________________________________________

Did my masters from IIT-M in Advanced Manufacturing Technology and working mainly on C++ in CAD domain from 2004 onwards.
Working on web technologies using Angular 7.0 and above, HTML5, CSS3 from 2015.

Comments and Discussions

 
GeneralMy vote of 1 Pin
Sivaraman Dhamodharan30-Jan-13 19:37
Sivaraman Dhamodharan30-Jan-13 19:37 
GeneralRe: My vote of 1 Pin
Lakamraju Raghuram31-Jan-13 1:08
Lakamraju Raghuram31-Jan-13 1:08 
GeneralSorry. I am not convinced. Memory leak detection should be d... Pin
Lakamraju Raghuram27-Jan-12 2:14
Lakamraju Raghuram27-Jan-12 2:14 
GeneralWill there be any additional leaks in release mode compared ... Pin
Lakamraju Raghuram26-Jan-12 22:21
Lakamraju Raghuram26-Jan-12 22:21 
GeneralRe: But you can't check the memory leaks of a release builds wit... Pin
Octopod26-Jan-12 23:08
Octopod26-Jan-12 23:08 
But you can't check the memory leaks of a release builds with the _CrtDumpMemoryLeaks trick. You can't always use debug build, for example when doing a diagnostic in production context. In addition, as you point, release builds can have different behavior.

Coming to the thrid party code, the callstack shows you the code that make call to the third party, which can lead you to understanding a wrong use of this third party code. And sometimes you have the .pdb of release third party code, revealing the full callstack (check Symbols servers, http://msdn.microsoft.com/en-us/library/windows/desktop/ee416588(v=vs.85).aspx#ID4EUG, it might be of interest).

About the VS2010 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.
GeneralReason for my vote of 2 Thank you for this hint for who don'... Pin
Octopod26-Jan-12 21:56
Octopod26-Jan-12 21:56 

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

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