这个挺有用的。记录一下.只适用于windows环境。
首先在代码头中加入:
1 2 3 4 5 6 7 8 9 10 11 12 13 | //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> |
然后在程序最后加上:
1 2 3 4 5 | #if USING_LEAK_CHECK printf ( "check memory leak ...\n" ); _CrtDumpMemoryLeaks(); printf ( "check over.\n" ); #endif |
在debug模式下进行调试,可以检测到常规的内存泄漏问题。
测试了一下,效果不错:
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步