Skip to content

Instantly share code, notes, and snippets.

@Maximus5
Forked from qpfiffer/test.cpp
Created August 13, 2020 13:08
Show Gist options
  • Save Maximus5/f9bfff6952feedd616b32455f0e1cafe to your computer and use it in GitHub Desktop.
Save Maximus5/f9bfff6952feedd616b32455f0e1cafe to your computer and use it in GitHub Desktop.
C++ Memory Leak Detection in VS2010
#ifdef _DEBUG
#include <ostream>
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#define new DEBUG_NEW
#endif
// ...
#ifdef _WIN32
_CrtDumpMemoryLeaks();
#endif
// Update 10/18/2011. Better to use the following for multiple exit points:
// add this code in main
#ifdef _DEBUG
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
// Breaking on a certain allocation:
_CrtSetBreakAlloc(137); // Will break on the 137th alloc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment