关于内存泄漏的一个问题。哪位大侠帮我解疑?
C/C++本地代码调试
关于内存泄漏的一个问题。哪位大侠帮我解疑?
Alex.xu
2009-07-23, 13:38 下午
问题如下:程序运行一段时间后,进程虚拟内存达到2G的上限。 我现在需要分析出来内存的分布情况。就是说哪些组件或者线程占用了较大的内存。
>!address
-------------------- Usage SUMMARY --------------------------
TotSize ( KB) Pct(Tots) Pct(Busy) Usage
3f04a000 ( 1032488) : 49.23% 52.57% : RegionUsageIsVAD
81c5000 ( 132884) : 06.34% 00.00% : RegionUsageFree
eef8000 ( 244704) : 11.67% 12.46% : RegionUsageImage
6e00000 ( 112640) : 05.37% 05.73% : RegionUsageStack
6e000 ( 440) : 00.02% 00.02% : RegionUsageTeb
2307a000 ( 573928) : 27.37% 29.22% : 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: 77e2b000 (1964204 KB)
-------------------- Type SUMMARY --------------------------
TotSize ( KB) Pct(Tots) Usage
81c5000 ( 132884) : 06.34% :
f1ac000 ( 247472) : 11.80% : MEM_IMAGE
47e3000 ( 73612) : 03.51% : MEM_MAPPED
6449c000 ( 1643120) : 78.35% : MEM_PRIVATE
-------------------- State SUMMARY --------------------------
TotSize ( KB) Pct(Tots) Usage
6c672000 ( 1776072) : 84.69% : MEM_COMMIT
81c5000 ( 132884) : 06.34% : MEM_FREE
b7b9000 ( 188132) : 08.97% : MEM_RESERVE
明显可以看到 mem_commit + mem_reserve占用了总内存的 92%。
接着分析heap信息
0:084> !heap -s
LFH Key : 0x0d3db197
Termination on corruption : DISABLED
Heap Flags Reserv Commit Virt Free List UCR Virt Lock Fast
(k) (k) (k) (k) length blocks cont. heap
-----------------------------------------------------------------------------
Virtual block: 190b0000 - 190b0000 (size 00000000)
Virtual block: 4a170000 - 4a170000 (size 00000000)
Virtual block: 2a0e0000 - 2a0e0000 (size 00000000)
Virtual block: 2d120000 - 2d120000 (size 00000000)
Virtual block: 2f900000 - 2f900000 (size 00000000)
Virtual block: 25670000 - 25670000 (size 00000000)
006a0000 00000002 32576 24976 32576 2214 619 6 6 a LFH
00010000 00008000 64 12 64 10 1 1 0 0
Virtual block: 0ff00000 - 0ff00000 (size 00000000)
Virtual block: 10030000 - 10030000 (size 00000000)
Virtual block: 1bfb0000 - 1bfb0000 (size 00000000)
Virtual block: 1dda0000 - 1dda0000 (size 00000000)
Virtual block: 1ee30000 - 1ee30000 (size 00000000)
Virtual block: 21f30000 - 21f30000 (size 00000000)
00350000 00001002 3136 2176 3136 117 46 3 6 0 LFH
012b0000 00001002 1088 872 1088 5 10 2 0 0 LFH
Virtual block: 0c270000 - 0c270000 (size 00000000)
Virtual block: 16fe0000 - 16fe0000 (size 00000000)
Virtual block: 16f40000 - 16f40000 (size 00000000)
Virtual block: 17b80000 - 17b80000 (size 00000000)
Virtual block: 21490000 - 21490000 (size 00000000)
Virtual block: 21770000 - 21770000 (size 00000000)
Virtual block: 19fc0000 - 19fc0000 (size 00000000)
Virtual block: 16380000 - 16380000 (size 00000000)
Virtual block: 17c20000 - 17c20000 (size 00000000)
Virtual block: 2dea0000 - 2dea0000 (size 00000000)
Virtual block: 21bf0000 - 21bf0000 (size 00000000)
Virtual block: 22040000 - 22040000 (size 00000000)
Virtual block: 26240000 - 26240000 (size 00000000)
Virtual block: 2f4f0000 - 2f4f0000 (size 00000000)
Virtual block: 27a60000 - 27a60000 (size 00000000)
Virtual block: 28bd0000 - 28bd0000 (size 00000000)
Virtual block: 2fde0000 - 2fde0000 (size 00000000)
Virtual block: 300f0000 - 300f0000 (size 00000000)
Virtual block: 27c30000 - 27c30000 (size 00000000)
Virtual block: 33ca0000 - 33ca0000 (size 00000000)
Virtual block: 28760000 - 28760000 (size 00000000)
Virtual block: 30400000 - 30400000 (size 00000000)
Virtual block: 16190000 - 16190000 (size 00000000)
Virtual block: 1c980000 - 1c980000 (size 00000000)
Virtual block: 1d940000 - 1d940000 (size 00000000)
Virtual block: 141b0000 - 141b0000 (size 00000000)
Virtual block: 1da30000 - 1da30000 (size 00000000)
Virtual block: 206b0000 - 206b0000 (size 00000000)
Virtual block: 208e0000 - 208e0000 (size 00000000)
Virtual block: 211f0000 - 211f0000 (size 00000000)
Virtual block: 52070000 - 52070000 (size 00000000)
Virtual block: 54a60000 - 54a60000 (size 00000000)
Virtual block: 53280000 - 53280000 (size 00000000)
Virtual block: 55280000 - 55280000 (size 00000000)
Virtual block: 5b250000 - 5b250000 (size 00000000)
Virtual block: 5b660000 - 5b660000 (size 00000000)
Virtual block: 5b830000 - 5b830000 (size 00000000)
Virtual block: 5bb40000 - 5bb40000 (size 00000000)
Virtual block: 5cef0000 - 5cef0000 (size 00000000)
Virtual block: 5d200000 - 5d200000 (size 00000000)
Virtual block: 5d330000 - 5d330000 (size 00000000)
Virtual block: 5db30000 - 5db30000 (size 00000000)
Virtual block: 5df40000 - 5df40000 (size 00000000)
Virtual block: 5e110000 - 5e110000 (size 00000000)
Virtual block: 5e530000 - 5e530000 (size 00000000)
Virtual block: 5e830000 - 5e830000 (size 00000000)
Virtual block: 63370000 - 63370000 (size 00000000)
Virtual block: 66eb0000 - 66eb0000 (size 00000000)
Virtual block: 68780000 - 68780000 (size 00000000)
Virtual block: 7a260000 - 7a260000 (size 00000000)
Virtual block: 65020000 - 65020000 (size 00000000)
Virtual block: 6da00000 - 6da00000 (size 00000000)
Virtual block: 6e8d0000 - 6e8d0000 (size 00000000)
Virtual block: 734a0000 - 734a0000 (size 00000000)
Virtual block: 77ab0000 - 77ab0000 (size 00000000)
Virtual block: 63ee0000 - 63ee0000 (size 00000000)
Virtual block: 64360000 - 64360000 (size 00000000)
Virtual block: 64140000 - 64140000 (size 00000000)
Virtual block: 65ed0000 - 65ed0000 (size 00000000)
Virtual block: 661e0000 - 661e0000 (size 00000000)
Virtual block: 664f0000 - 664f0000 (size 00000000)
Virtual block: 66800000 - 66800000 (size 00000000)
Virtual block: 77dc0000 - 77dc0000 (size 00000000)
Virtual block: 66930000 - 66930000 (size 00000000)
Virtual block: 6e5b0000 - 6e5b0000 (size 00000000)
Virtual block: 66c30000 - 66c30000 (size 00000000)
Virtual block: 795a0000 - 795a0000 (size 00000000)
Virtual block: 78db0000 - 78db0000 (size 00000000)
Virtual block: 7b260000 - 7b260000 (size 00000000)
Virtual block: 785c0000 - 785c0000 (size 00000000)
Virtual block: 7ba50000 - 7ba50000 (size 00000000)
00330000 00001002 64000 57504 64000 569 587 29 71 8f LFH
013c0000 00001002 1088 176 1088 17 7 2 0 0 LFH
01550000 00041002 256 124 256 2 7 1 0 0 LFH
025b0000 00001002 64 4 64 2 1 1 0 0
027b0000 00001002 1088 184 1088 18 7 2 0 0 LFH
02970000 00001002 1024 1024 1024 1022 3 1 0 0
028c0000 00001002 1280 384 1280 5 22 2 0 0 LFH
03100000 00001002 3136 2492 3136 23 56 3 0 0 LFH
02960000 00001002 3136 2352 3136 327 45 3 0 0 LFH
External fragmentation 13 % (45 free blocks)
03a10000 00001002 256 28 256 2 1 1 0 0
03910000 00001002 1088 236 1088 61 6 2 0 0 LFH
04370000 00001001 64 40 64 2 1 1 0 bad
048e0000 00001002 1088 172 1088 29 12 2 0 0 LFH
04aa0000 00001002 1088 112 1088 3 5 2 0 0 LFH
07e70000 00001002 1024 1024 1024 1022 3 1 0 0
Virtual block: 0e700000 - 0e700000 (size 00000000)
Virtual block: 11180000 - 11180000 (size 00000000)
Virtual block: 2bdc0000 - 2bdc0000 (size 00000000)
Virtual block: 2cea0000 - 2cea0000 (size 00000000)
08490000 00001002 7232 4516 7232 372 38 4 4 0 LFH
08410000 00001002 15424 8904 15424 176 114 5 0 0 LFH
09480000 00011002 256 4 256 2 1 1 0 0
09020000 00001002 1088 340 1088 249 12 2 0 0 LFH
0d330000 00001002 1088 160 1088 6 4 2 0 0 LFH
129a0000 00001002 1088 108 1088 4 5 2 0 0 LFH
14170000 00001003 1280 1136 1280 1055 57 2 0 bad
External fragmentation 92 % (57 free blocks)
12b90000 00001003 256 4 256 2 1 1 0 bad
0a250000 00001003 256 4 256 2 1 1 0 bad
14130000 00001003 256 4 256 2 1 1 0 bad
14340000 00001003 256 4 256 2 1 1 0 bad
17d60000 00041002 256 112 256 1 16 1 0 0 LFH
Virtual block: 17da0000 - 17da0000 (size 00000000)
Virtual block: 1c7b0000 - 1c7b0000 (size 00000000)
Virtual block: 1cf60000 - 1cf60000 (size 00000000)
Virtual block: 1dd20000 - 1dd20000 (size 00000000)
Virtual block: 1e550000 - 1e550000 (size 00000000)
Virtual block: 1e840000 - 1e840000 (size 00000000)
Virtual block: 25c30000 - 25c30000 (size 00000000)
Virtual block: 344a0000 - 344a0000 (size 00000000)
Virtual block: 1f590000 - 1f590000 (size 00000000)
Virtual block: 20210000 - 20210000 (size 00000000)
Virtual block: 26030000 - 26030000 (size 00000000)
Virtual block: 2daa0000 - 2daa0000 (size 00000000)
Virtual block: 30700000 - 30700000 (size 00000000)
Virtual block: 32440000 - 32440000 (size 00000000)
Virtual block: 348a0000 - 348a0000 (size 00000000)
Virtual block: 34aa0000 - 34aa0000 (size 00000000)
Virtual block: 35b10000 - 35b10000 (size 00000000)
Virtual block: 213e0000 - 213e0000 (size 00000000)
Virtual block: 21960000 - 21960000 (size 00000000)
Virtual block: 34ea0000 - 34ea0000 (size 00000000)
Virtual block: 35f10000 - 35f10000 (size 00000000)
Virtual block: 36200000 - 36200000 (size 00000000)
Virtual block: 393d0000 - 393d0000 (size 00000000)
Virtual block: 395d0000 - 395d0000 (size 00000000)
Virtual block: 41ab0000 - 41ab0000 (size 00000000)
Virtual block: 438c0000 - 438c0000 (size 00000000)
Virtual block: 23010000 - 23010000 (size 00000000)
Virtual block: 230b0000 - 230b0000 (size 00000000)
Virtual block: 397d0000 - 397d0000 (size 00000000)
Virtual block: 41eb0000 - 41eb0000 (size 00000000)
Virtual block: 43cc0000 - 43cc0000 (size 00000000)
Virtual block: 43ec0000 - 43ec0000 (size 00000000)
Virtual block: 476d0000 - 476d0000 (size 00000000)
Virtual block: 478d0000 - 478d0000 (size 00000000)
Virtual block: 47cd0000 - 47cd0000 (size 00000000)
Virtual block: 24220000 - 24220000 (size 00000000)
Virtual block: 242c0000 - 242c0000 (size 00000000)
Virtual block: 4a960000 - 4a960000 (size 00000000)
Virtual block: 4ab60000 - 4ab60000 (size 00000000)
Virtual block: 4ad60000 - 4ad60000 (size 00000000)
Virtual block: 4c030000 - 4c030000 (size 00000000)
Virtual block: 4c230000 - 4c230000 (size 00000000)
Virtual block: 4c430000 - 4c430000 (size 00000000)
Virtual block: 4c830000 - 4c830000 (size 00000000)
Virtual block: 27390000 - 27390000 (size 00000000)
Virtual block: 27430000 - 27430000 (size 00000000)
Virtual block: 4cc30000 - 4cc30000 (size 00000000)
Virtual block: 4ce30000 - 4ce30000 (size 00000000)
Virtual block: 4d030000 - 4d030000 (size 00000000)
Virtual block: 4d230000 - 4d230000 (size 00000000)
Virtual block: 4d430000 - 4d430000 (size 00000000)
Virtual block: 4d630000 - 4d630000 (size 00000000)
Virtual block: 4da30000 - 4da30000 (size 00000000)
Virtual block: 28ee0000 - 28ee0000 (size 00000000)
Virtual block: 2f9f0000 - 2f9f0000 (size 00000000)
Virtual block: 4de30000 - 4de30000 (size 00000000)
Virtual block: 4e030000 - 4e030000 (size 00000000)
Virtual block: 4e230000 - 4e230000 (size 00000000)
Virtual block: 4e430000 - 4e430000 (size 00000000)
Virtual block: 4e630000 - 4e630000 (size 00000000)
Virtual block: 4e830000 - 4e830000 (size 00000000)
Virtual block: 4ec30000 - 4ec30000 (size 00000000)
Virtual block: 2fa90000 - 2fa90000 (size 00000000)
Virtual block: 2fb30000 - 2fb30000 (size 00000000)
Virtual block: 4f030000 - 4f030000 (size 00000000)
Virtual block: 4f230000 - 4f230000 (size 00000000)
Virtual block: 4f430000 - 4f430000 (size 00000000)
Virtual block: 4f630000 - 4f630000 (size 00000000)
Virtual block: 4f830000 - 4f830000 (size 00000000)
Virtual block: 4fa30000 - 4fa30000 (size 00000000)
Virtual block: 4fe30000 - 4fe30000 (size 00000000)
Virtual block: 30900000 - 30900000 (size 00000000)
Virtual block: 32640000 - 32640000 (size 00000000)
Virtual block: 50230000 - 50230000 (size 00000000)
Virtual block: 50430000 - 50430000 (size 00000000)
Virtual block: 50630000 - 50630000 (size 00000000)
Virtual block: 50830000 - 50830000 (size 00000000)
Virtual block: 50a30000 - 50a30000 (size 00000000)
Virtual block: 50c30000 - 50c30000 (size 00000000)
Virtual block: 23150000 - 23150000 (size 00000000)
Virtual block: 274d0000 - 274d0000 (size 00000000)
Virtual block: 28960000 - 28960000 (size 00000000)
Virtual block: 51d70000 - 51d70000 (size 00000000)
1c870000 00001002 7232 3300 7232 4 6 4 83 0 LFH
35280000 00001002 1088 440 1088 3 4 2 0 0 LFH
-----------------------------------------------------------------------------
上面的信息我就产生了两个疑问:
Virtual block: 51d70000 - 51d70000 (size 00000000) 这种信息到底代码什么意思?
因为我只知道:
006a0000 00000002 32576 24976 32576 2214 619 6 6 a LFH 代码一个堆的信息
我如果去掉这些所谓的Virtual block 信息。heap -s 信息精简为如下:
Heap Flags Reserv Commit Virt Free List U CR Virt Lock F ast
(k) (k) (k) (k) length bloc ks cont. heap
006a0000 2 32576 24976 32576 2214 619 6 6 a LFH
10000 8000 64 12 64 10 1 1 0 0
350000 1002 3136 2176 3136 117 46 3 6 0 LFH
012b0000 1002 1088 872 1088 5 10 2 0 0 LFH
330000 1002 64000 57504 64000 569 587 29 71 8f LFH
013c0000 1002 1088 176 1088 17 7 2 0 0 LFH
1550000 41002 256 124 256 2 7 1 0 0 LFH
025b0000 1002 64 4 64 2 1 1 0 0
027b0000 1002 1088 184 1088 18 7 2 0 0 LFH
2970000 1002 1024 1024 1024 1022 3 1 0 0
028c0000 1002 1280 384 1280 5 22 2 0 0 LFH
3100000 1002 3136 2492 3136 23 56 3 0 0 LFH
2960000 1002 3136 2352 3136 327 45 3 0 0 LFH
03a10000 1002 256 28 256 2 1 1 0 0
3910000 1002 1088 236 1088 61 6 2 0 0 LFH
4370000 1001 64 40 64 2 1 1 0 bad
4.80E+01 1002 1088 172 1088 29 12 2 0 0 LFH
04aa0000 1002 1088 112 1088 3 5 2 0 0 LFH
07e70000 1002 1024 1024 1024 1022 3 1 0 0
8490000 1002 7232 4516 7232 372 38 4 4 0 LFH
8410000 1002 15424 8904 15424 176 114 5 0 0 LFH
9480000 11002 256 4 256 2 1 1 0 0
9020000 1002 1088 340 1088 249 12 2 0 0 LFH
0d330000 1002 1088 160 1088 6 4 2 0 0 LFH
129a0000 1002 1088 108 1088 4 5 2 0 0 LFH
14170000 1003 1280 1136 1280 1055 57 2 0 bad
12b90000 1003 256 4 256 2 1 1 0 bad
0a250000 1003 256 4 256 2 1 1 0 bad
14130000 1003 256 4 256 2 1 1 0 bad
14340000 1003 256 4 256 2 1 1 0 bad
17d60000 41002 256 112 256 1 16 1 0 0 LFH
1c870000 1002 7232 3300 7232 4 6 4 83 0 LFH
35280000 1002 1088 440 1088 3 4 2 0 0 LFH
sum 总和: 153600 112928 153600
Re: 关于内存泄漏的一个问题。哪位大侠帮我解疑?
Alex.xu
2009-07-23, 13:41 下午
接着看上面的东西: Reserv 的sum是153600kb Commit 的sum是112928 kb
与上面的!address 输出结果相差甚远
-------------------- State SUMMARY --------------------------
TotSize ( KB) Pct(Tots) Usage
6c672000 ( 1776072) : 84.69% : MEM_COMMIT
81c5000 ( 132884) : 06.34% : MEM_FREE
b7b9000 ( 188132) : 08.97% : MEM_RESERVE
请问各位造成这种情况的原因是什么? !heap -s的信息感觉不全呢?