内存泄露的快速寻找方法
http://blog.csdn.net/ly402609921/article/details/5705663
看看代码:
// MemoryLeak.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <assert.h>
#ifdef _DEBUG
#define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__)
#else
#define DEBUG_CLIENTBLOCK
#endif
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#ifdef _DEBUG
#define new DEBUG_CLIENTBLOCK
#endif //此部分用于使_CrtDumpMemoryLeaks输出内存泄漏文件名和行号信息默认不会输出相关信息
int _tmain(int argc, _TCHAR* argv[])
{
// atexit(Exit);
int* p = new int;
_CrtDumpMemoryLeaks();
return 0;
}
进入调试模式,不要直接运行,可以直接定位内存泄漏的位置。

本文介绍了一种在调试模式下使用Visual C++特定宏定义和调试库来定位内存泄漏位置的方法。通过示例代码展示了如何让_CrtDumpMemoryLeaks()函数输出更详细的内存泄漏信息。
333

被折叠的 条评论
为什么被折叠?



