Posted By

jimfred on 11/12/08


Tagged

c memory visual Studio leak


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

poldaker
khouser


Visual Studio debug tools to detect and debug memory leaks by setting a breakpoint on a particular memory allocation.


 / Published in: C++
 

URL: http://msdn.microsoft.com/en-us/library/w2fhc9a3%28VS.80%29.aspx

The Visual Studio output window will display "Detected memory leaks!" with a memory allocation number, for example, {145}. See Memory Leak Detection Enabling.

Using the debugger (without changing code) see: http://msdn.microsoft.com/en-us/library/w2fhc9a3%28VS.80%29.aspx

  1. // Using the debugger (without changing code) see: http://msdn.microsoft.com/en-us/library/w2fhc9a3%28VS.80%29.aspx
  2.  
  3. // Includes...
  4. #define _CRTDBG_MAP_ALLOC
  5. #include <stdlib.h>
  6. #include <crtdbg.h>
  7.  
  8.  
  9. // Set this debug flag
  10. _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
  11.  
  12. // break on a particular allocation as indicated in visual studio as {145}.
  13. _crtBreakAlloc = 145;

Report this snippet  

You need to login to post a comment.