这个挺有用的。记录一下.只适用于windows环境。
首先在代码头中加入:
//if using the check of leak memory #define USING_LEAK_CHECK 1 #ifndef _crtdbg_map_alloc #define _crtdbg_map_alloc #endif #include <stdlib.h> #if USING_LEAK_CHECK #include <crtdbg.h> #endif #include <stdio.h>
然后在程序最后加上:
#if USING_LEAK_CHECK
printf("check memory leak ...\n");
_CrtDumpMemoryLeaks();
printf("check over.\n");
#endif
在debug模式下进行调试,可以检测到常规的内存泄漏问题。
测试了一下,效果不错:
