-
-
Save Maximus5/f9bfff6952feedd616b32455f0e1cafe to your computer and use it in GitHub Desktop.
C++ Memory Leak Detection in VS2010
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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