LeakDiag是一个监测内存泄漏的工具,可以用来精确地找到内存泄露一直到代码行。它使用微软的Detours 技术,拦截指定内存分配的调用并跟踪各种调用栈,并报告已分配但尚未释放的内存,这一信息允许让我们在排除一个内存泄露问题时,能精确查看哪些组件进行了该分配。使用正确的调试符号,我们甚至可以看见请求分配的代码行。
关于detours: http://research.microsoft.com/en-us/projects/detours/
LeakDiag 目前支持六种类型的泄漏检查:
Virtual Allocator
Heap Allocator
MPHeap Allocator
COM AllocatorCoTaskMem
COM Private Allocator
C Runtime Allocator
版本:1.25
下载地址:
或者:
http://d.download.csdn.net/down/1168689/cloveroger
使用方法:
1、编写一个包含内存泄漏问题的C程序,例如LeakDiagTest1:
#include <stdlib.h>
int main(int argc, char* argv[])
{
char *p = NULL;
while (getc(stdin))
{
p = (char *)malloc(1024);
//delete(p);
}
return 0;
}
2、运行C程序的可执行文件LeakDiagTest1.exe,打开LeakDiag
在进程列表中选择LeakDiagTest1.exe
在Memory allocators列表中选择“Windows Heap Allocator”
按Start开始进行监测
3、在LeakDiagTest1运行过程中,可多次按Log进行内存信息收集(“快照”),最后按Stop停止监测
4、打开logs目录中的日志文件进行分析,可发现有内存泄漏现象:
<FRAME num=”0″ dll=”LeakDiagTest1.exe” function =”_heap_alloc_base” offset=”0x55″ filename=”malloc.c” line=”161″ addr=”0x4035F5″ />
<FRAME num=”1″ dll=”LeakDiagTest1.exe” function =”_heap_alloc_dbg” offset=”0x1A2″ filename=”dbgheap.c” line=”367″ addr=”0x401352″ />
<FRAME num=”2″ dll=”LeakDiagTest1.exe” function =”_nh_malloc_dbg” offset=”0x19″ filename=”dbgheap.c” line=”242″ addr=”0x401159″ />
<FRAME num=”3″ dll=”LeakDiagTest1.exe” function =”malloc” offset=”0x18″ filename=”dbgheap.c” line=”130″ addr=”0x4010E8″ />
<FRAME num=”4″ dll=”LeakDiagTest1.exe” function =”main” offset=”0x76″ filename=”E:\tmp\LeakDiagTest1\LeakDiagTest1.cpp” line=”13″ addr=”0x401086″ />
5、用LDGrapher可以图形的方式更加直观地看到多个快照点连续的内存泄漏情况
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/Testing_is_believing/archive/2010/03/01/5335731.aspx
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/zdl1016/archive/2010/03/02/5339525.aspx
- 本文固定链接: http://jingyan.idoubi.net/2689.html
- 转载请注明: 游戏创作者大陆 于 逗分享开发经验 发表