GFlags和UMDH与WinDbg一样,都是Debugging Tools for Windows里的工具。

1.设置符号路径

   去微软官网下载对应的操作系统的符号安装文件,并安装到某个目录,如C:\WINDOWS\Symbols。

   设置符号路径_NT_SYMBOL_PATH环境变量srv*C:/WINDOWS/Symbols*http://msdl.microsoft.com/download/symbols。

2.编写测试程序MemoryLeakTest

 1 #include <iostream>
 2 using namespace std;
 3 
 4 int NewMemoryTest1()
 5 {
 6     char *p = new char[1024];
 7     memset(p, 0x00, 1024*sizeof(char));
 8     return 0;
 9 }
10 
11 int MallocMemoryTest1()
12 {
13     char *p = (char*)malloc(1024*sizeof(char));
14     memset(p, 0x00, 1024*sizeof(char));
15     return 0;
16 }
17 
18 int main()
19 {
20     int i = 0;
21     cin >> i;
22     NewMemoryTest1();
23     MallocMemoryTest1();
24     cin >> i;
25 
26     return 0;
27 }

3.打开Windows命令行窗口,在命令行中输入:GFlags /i MemoryLeakTest.exe +ust。

输出:

Current Registry Settings for MemoryLeakTest.exe executable are: 00001000

ust - Create user mode stack trace database

4.运行MemoryLeakTest.exe程序。

5.在命令行中输入:UMDH -pn:MemoryLeakTest.exe -f:D:\Snap1.txt。

6.在MemoryLeakTest.exe程序命令行中输输入任意数字,使程序执行NewMemoryTest1和MallocMemoryTest1函数。

7.在命令行中输入:UMDH -pn:MemoryLeakTest.exe -f:D:\Snap2.txt。

8.在命令行中输入:UMDH -d D:\Snap1.txt D:\Snap2.txt > D:\Result.txt。

在D:\Result.txt中有内存泄露的信息,可对比程序源代码进行分析。

相关文章:

  • 2022-12-23
  • 2022-01-02
  • 2022-02-09
  • 2022-12-23
  • 2022-02-19
  • 2022-12-23
  • 2021-05-16
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-02
  • 2021-12-04
相关资源
相似解决方案