本机内存泄漏 - 如何查找分配源的调用堆栈

发布于 2024-12-13 00:42:09 字数 3019 浏览 3 评论 0原文

根据 !address -summary 命令的以下输出,我认为我遇到了本机内存泄漏。为了确定发生这些分配的调用堆栈,我正在关注 http:// /www.codeproject.com/KB/cpp/MemoryLeak.aspx

0:000> !address -summary  
 TEB 7efdd000 in range 7efdb000 7efde000  
 TEB 7efda000 in range 7efd8000 7efdb000  
 TEB 7efd7000 in range 7efd5000 7efd8000  
 TEB 7efaf000 in range 7efad000 7efb0000  
 TEB 7efac000 in range 7efaa000 7efad000  
 ProcessParametrs 00441b78 in range 00440000 00540000  
 Environment 004407f0 in range 00440000 00540000  

-------------------- Usage SUMMARY --------------------------  
    TotSize (      KB)   Pct(Tots) Pct(Busy)   Usage  
    551a000 (   87144) : 04.16%    14.59%    : RegionUsageIsVAD  
   5b8d3000 ( 1499980) : 71.53%    00.00%    : RegionUsageFree  
    2cc3000 (   45836) : 02.19%    07.68%    : RegionUsageImage  
     4ff000 (    5116) : 00.24%    00.86%    : RegionUsageStack  
          0 (       0) : 00.00%    00.00%    : RegionUsageTeb  
   1c040000 (  459008) : 21.89%    76.87%    : RegionUsageHeap  
          0 (       0) : 00.00%    00.00%    : RegionUsagePageHeap  
       1000 (       4) : 00.00%    00.00%    : RegionUsagePeb  
          0 (       0) : 00.00%    00.00%    : RegionUsageProcessParametrs  
          0 (       0) : 00.00%    00.00%    : RegionUsageEnvironmentBlock  
       Tot: 7fff0000 (2097088 KB) Busy: 2471d000 (597108 KB)  


0:000> !heap -s  
LFH Key                   : 0x7fdcf95f  
Termination on corruption : DISABLED  
  Heap     Flags   Reserv  Commit  Virt   Free  List   UCR  Virt  Lock  Fast   
                    (k)     (k)    (k)     (k) length      blocks cont. heap   
-----------------------------------------------------------------------------  
00440000 00000002  453568 436656 453568     62    54    32    0      0   LFH    
006b0000 00001002      64     16     64      4     2     1    0      0        
002b0000 00041002     256      4    256      2     1     1    0      0        
00620000 00001002      64     16     64      5     2     1    0      0        
00250000 00001002      64     16     64      4     2     1    0      0        
007d0000 00041002     256      4    256      0     1     1    0      0        
005c0000 00001002    1088    388   1088      7    17     2    0      0   LFH  
02070000 00041002     256      4    256      1     1     1    0      0        
02270000 00041002     256    144    256      0     1     1    0      0   LFH  
04e10000 00001002    3136   1764   3136    384    36     3    0      0   LFH  
    External fragmentation  21 % (36 free blocks)  
-----------------------------------------------------------------------------  

但是当我运行 !heap -p –a 命令时,我没有得到任何调用堆栈,只有以下内容。有什么想法如何获取分配源的调用堆栈吗?

0:000> !heap -p -a 0218e008  
    address 0218e008 found in  
    _HEAP @ 4e10000  
      HEAP_ENTRY Size Prev Flags    UserPtr UserSize - state  
        0218e000 001c 0000  [00]   0218e008    000d4 - (busy)  

Based on following output of !address -summary command, I think I have got a native memory leak. In order to deterine the callstack on where these allocations are happening, I am following article at http://www.codeproject.com/KB/cpp/MemoryLeak.aspx

0:000> !address -summary  
 TEB 7efdd000 in range 7efdb000 7efde000  
 TEB 7efda000 in range 7efd8000 7efdb000  
 TEB 7efd7000 in range 7efd5000 7efd8000  
 TEB 7efaf000 in range 7efad000 7efb0000  
 TEB 7efac000 in range 7efaa000 7efad000  
 ProcessParametrs 00441b78 in range 00440000 00540000  
 Environment 004407f0 in range 00440000 00540000  

-------------------- Usage SUMMARY --------------------------  
    TotSize (      KB)   Pct(Tots) Pct(Busy)   Usage  
    551a000 (   87144) : 04.16%    14.59%    : RegionUsageIsVAD  
   5b8d3000 ( 1499980) : 71.53%    00.00%    : RegionUsageFree  
    2cc3000 (   45836) : 02.19%    07.68%    : RegionUsageImage  
     4ff000 (    5116) : 00.24%    00.86%    : RegionUsageStack  
          0 (       0) : 00.00%    00.00%    : RegionUsageTeb  
   1c040000 (  459008) : 21.89%    76.87%    : RegionUsageHeap  
          0 (       0) : 00.00%    00.00%    : RegionUsagePageHeap  
       1000 (       4) : 00.00%    00.00%    : RegionUsagePeb  
          0 (       0) : 00.00%    00.00%    : RegionUsageProcessParametrs  
          0 (       0) : 00.00%    00.00%    : RegionUsageEnvironmentBlock  
       Tot: 7fff0000 (2097088 KB) Busy: 2471d000 (597108 KB)  


0:000> !heap -s  
LFH Key                   : 0x7fdcf95f  
Termination on corruption : DISABLED  
  Heap     Flags   Reserv  Commit  Virt   Free  List   UCR  Virt  Lock  Fast   
                    (k)     (k)    (k)     (k) length      blocks cont. heap   
-----------------------------------------------------------------------------  
00440000 00000002  453568 436656 453568     62    54    32    0      0   LFH    
006b0000 00001002      64     16     64      4     2     1    0      0        
002b0000 00041002     256      4    256      2     1     1    0      0        
00620000 00001002      64     16     64      5     2     1    0      0        
00250000 00001002      64     16     64      4     2     1    0      0        
007d0000 00041002     256      4    256      0     1     1    0      0        
005c0000 00001002    1088    388   1088      7    17     2    0      0   LFH  
02070000 00041002     256      4    256      1     1     1    0      0        
02270000 00041002     256    144    256      0     1     1    0      0   LFH  
04e10000 00001002    3136   1764   3136    384    36     3    0      0   LFH  
    External fragmentation  21 % (36 free blocks)  
-----------------------------------------------------------------------------  

But when I run !heap -p –a command, I don’t get any callstack, just the following. Any ideas how to get callstack of allocations source?

0:000> !heap -p -a 0218e008  
    address 0218e008 found in  
    _HEAP @ 4e10000  
      HEAP_ENTRY Size Prev Flags    UserPtr UserSize - state  
        0218e000 001c 0000  [00]   0218e008    000d4 - (busy)  

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

扭转时空 2024-12-20 00:42:09

你应该使用除油器。它是强大的调试工具。

You should use deleaker. It's powerful tool for debuging.

童话 2024-12-20 00:42:09

Linux 使用 valgrind,Windows 使用 deleaker。

use valgrind for linux and deleaker for windows.

歌入人心 2024-12-20 00:42:09

如果您没有从 !heap -p -a 获得调用堆栈
原因可能是你没有正确使用gflags
请记住使用正确的名称,包括 .exe
尝试以交互方式启动它并转到图像选项卡,可能会更容易
尝试使用页堆,这也给出了调用堆栈

If you don't get a call stack from !heap -p -a
The reason can be that you have not used gflags correctly
Remeber to use correct name including .exe
Try to start it inteactivly and go to the image tab, might be easier
Try with page heap, that also gives call stack

一身仙ぐ女味 2024-12-20 00:42:09

我对 Windows 一无所知,但至少在 Unix 系统上,调试器(如 Linux 上的 gdb)对于理解调用堆栈很有用。

您还可以使用 Boehm 的保守垃圾收集器 来规避一些问题。在许多系统上,您还可以借助 valgrind 寻找内存泄漏

I know nothing about Windows, but at least on Unix systems a debugger (like gdb on Linux) is useful to understand callstacks.

And you could also circumvent some of your issues by using e.g. Boehm's conservative garbage collector. On many systems you can also hunt memory leaks with the help of valgrind

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文