环境:VS2013Update3
打印memory leak位置
Code Snippet // compile with cl /D_DEBUG /MDd /EHsc leak2.cpp #define _CRTDBG_MAP_ALLOC #include <iostream> #include <crtdbg.h> #ifdef _DEBUG #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) #define new DEBUG_NEW #endif int main() { char *a = new char[10]; char *b = (char*)malloc(20); _CrtDumpMemoryLeaks(); return 0; }
程序运行时,在memory leak位置block
BOOL Ccat8637_brandApp::InitInstance() { #ifdef _DEBUG //where detect memory leak,now will be break here! _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); _CrtSetBreakAlloc(9554); _CrtSetBreakAlloc(9553); _CrtSetBreakAlloc(9552); #endif ...ignore...
[1]Visual Leak Detector for Visual C++ 2008/2010/2012/2013
https://vld.codeplex.com/