从卦中看,当前进程有 13.6 G 的提交内存,NtHeap 占用了 13G,很明显这是非托管内存泄漏,既然是非托管泄漏,那就需要二番战,也就是让朋友开启 ust,或者启用应用程序验证器 (Application Verifier) 开启页堆,目的就是记录分配这块内存的源头,这里就让朋友用 gflags 开启下 ust,具体怎么开,这里就不介绍了,大家可以网上搜一下 。
2. 追踪 ust 加持下的调用栈有了 ust 的加持,接下来就可以继续分析,使用 !heap -s 观察下 nt 堆的布局 。
0:000> !heap -sSEGMENT HEAP ERROR: failed to initialize the extentionNtGlobalFlag enables following debugging aids for new heaps: stack back tracesLFH Key : 0x0000004c4f657ebfTermination on corruption : ENABLED Heap Flags Reserv Commit Virt Free List UCR Virt Lock Fast (k) (k) (k) (k) length blocks cont. heap-------------------------------------------------------------------------------------0000000000060000 08000002 32576 17212 32576 430 161 6 1 0 LFH0000000000010000 08008000 64 8 64 5 1 1 0 00000000008810000 08001002 1088 500 1088 15 5 2 0 0 LFH...0000000029fb0000 08001002 88320 67408 88320 32559 343 47 189 1b7 LFH External fragmentation 48 % (343 free blocks)0000000029870000 08001002 512 8 512 3 1 1 0 0...-------------------------------------------------------------------------------------从卦中看,commit 最大的也就是 67408k = 67M, 这和 13G 差的不是一星半点,如果你了解 NtHeap 的布局,应该知道当 分配内存 > 512k 的时候,会进入到 HEAP 的 VirtualAllocdBlocks 双向链表中,言外之意就是当你觉得内存对不上的时候,就要观察下这个链表了,即上图中的 Virt blocks 列,可以看到 handle=0000000029fb0000 的 Virt blocks=189,接下来继续下钻 handle=0000000029fb0000 这个堆 。
0:000> !heap -h 0000000029fb0000SEGMENT HEAP ERROR: failed to initialize the extentionIndex Address Name Debugging options enabled 23: 29fb0000 Segment at 0000000029fb0000 to 000000002a7b0000 (007eb000 bytes committed) Segment at 0000000026070000 to 0000000026170000 (000ff000 bytes committed) Segment at 0000000027d10000 to 0000000027f10000 (001f7000 bytes committed) Segment at 00000000318a0000 to 0000000031ca0000 (00400000 bytes committed) Segment at 0000000044a00000 to 0000000045200000 (005f1000 bytes committed) Segment at 000000004ae90000 to 000000004be60000 (00efc000 bytes committed) Segment at 000000005b3b0000 to 000000005c380000 (00e2e000 bytes committed) Segment at 000000005d8c0000 to 000000005e890000 (00cf1000 bytes committed) Segment at 000000005c380000 to 000000005d350000 (002e7000 bytes committed) Flags: 08001002 ForceFlags: 00000000 Granularity: 16 bytes ... Virtual Alloc List: 29fb0118 Unable to read nt!_HEAP_VIRTUAL_ALLOC_ENTRY structure at 0000000043500000 Uncommitted ranges: 29fb00f8
经验总结扩展阅读
- Bing 广告平台迁移到 .net6
- 冬奥会多久举行一次
- 第一次办信用卡哪个银行最好申请
- 抖音怎么一次性删掉赞
- 长城电子借记卡1类和2类的区别
- 微信怎么删除好友,微信好友怎么快速删除(微信怎么一次性删除所有的好友)
- 木偶奇遇记主要内容
- 二次供水指什么意思 二次供水和一次供水的区别
- 邮箱密码忘记了怎么找回
- 地球史上的第一次生物大灭绝