调试 方便地检测程序的内存泄漏 CMemoryState
2013-02-21 12:49
309 查看
MSDN:http://msdn.microsoft.com/zh-cn/library/0wzsd007%28v=vs.110%29.aspx
参考的博客:http://blog.csdn.net/yuanweihuayan/article/details/7426412
普通块
CRT 块
忽略块
客户端块。
程序在任何时间使用的最大内存(以字节为单位)
程序当前使用的总内存(以字节为单位)
oldMem.Checkpoint(); // 检测当前的内存使用情况
char* c = new char[6];
TRACE0("1-------------------\n");
oldMem.DumpAllObjectsSince(); // oldMem就检测到这里
TRACE0("2-------------------\n");
newMem.Checkpoint(); // 没有delete[] c
if (difMem.Difference(oldMem, newMem)) // 比较
{
TRACE0("Memory Lack!\n");
}
TRACE0("3-------------------\n");
difMem.DumpStatistics(); // 在Output中打印结果
TRACE0("4-------------------\n"); 输出
参考的博客:http://blog.csdn.net/yuanweihuayan/article/details/7426412
CMemoryState结构
方便地检测到您的程序的内存泄漏。struct CMemoryState
成员
void Checkpoint( );
获取一个快照(检查点)并将其存储
备注:成员函数 Difference 和 DumpAllObjectsSince 使用此快照数据。
BOOL Difference( const CMemoryState& oldState, const CMemoryState& newState );
计算类型之间 CMemoryState两个对象的差异
非零,如果两个内存状态不同的;否则为0。
void DumpAllObjectsSince( ) const;
转储所有当前分配的对象摘要从以前的检查点。即打印检查点到当前位置的内存分配情况
void DumpStatistics( ) const;
打印 CMemoryState 对象的内存分配统计信息
备注:可用块
普通块
CRT 块
忽略块
客户端块。
程序在任何时间使用的最大内存(以字节为单位)
程序当前使用的总内存(以字节为单位)
例子:
代码CMemoryState oldMem, newMem, difMem;
oldMem.Checkpoint(); // 检测当前的内存使用情况
char* c = new char[6];
TRACE0("1-------------------\n");
oldMem.DumpAllObjectsSince(); // oldMem就检测到这里
TRACE0("2-------------------\n");
newMem.Checkpoint(); // 没有delete[] c
if (difMem.Difference(oldMem, newMem)) // 比较
{
TRACE0("Memory Lack!\n");
}
TRACE0("3-------------------\n");
difMem.DumpStatistics(); // 在Output中打印结果
TRACE0("4-------------------\n"); 输出
1------------------- Dumping objects -> D:\20130204\testmfc\testmfcDlg.cpp(126) : {79} normal block at 0x005738A0, 6 bytes long. Data: < > CD CD CD CD CD CD Object dump complete. 2------------------- Memory Lack! 3------------------- 0 bytes in 0 Free Blocks. 6 bytes in 1 Normal Blocks. 0 bytes in 0 CRT Blocks. 0 bytes in 0 Ignore Blocks. 0 bytes in 0 Client Blocks. Largest number used: 0 bytes. Total allocations: 6 bytes. 4-------------------
相关文章推荐
- 应用CMemoryState动态检测内存泄漏
- VC++ 6.0 中如何使用 CRT 调试功能来检测内存泄漏
- 使用 CRT 调试功能来检测内存泄漏
- CMemoryState(MFC内存检测类)
- VC使用CRT调试功能检测内存泄漏
- VC使用CRT调试功能检测内存泄漏
- 关于c++检测内存泄露相关知识(windows程序调试)
- 关于c++检测内存泄露相关知识(windows程序调试)
- VC使用CRT调试功能来检测内存泄漏
- 简单内存泄漏检测方法 解决 Detected memory leaks! 问题
- CMemoryState(MFC内存检测类)
- VC++ 6.0 中如何使用 CRT 调试功能来检测内存泄漏
- 简单内存泄漏检测方法,解决Detected memory leaks!问题
- [转]简单内存泄漏检测方法 解决 Detected memory leaks! 问题
- 简单内存泄漏检测方法 解决 Detected memory leaks! 问题
- 简单内存泄漏检测方法 解决 Detected memory leaks!
- VC使用CRT调试功能来检测内存泄漏
- 简单内存泄漏检测方法 解决 Detected memory leaks! 问题
- 简单内存泄漏检测方法,解决Detected memory leaks!问题
- 简单内存泄漏检测方法 解决 Detected memory leaks