欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

另一种形式的OufOfMemoryException

程序员文章站 2022-07-07 22:38:48
内存中空闲空间不少,但是连续的空闲空间却只有100k。 0:000> !address -summary --- Usage Summary --------------...

内存中空闲空间不少,但是连续的空闲空间却只有100k。

0:000> !address -summary

--- Usage Summary ---------------- RgnCount ----------- Total Size -------- %ofBusy %ofTotal
<unknown>                              6853          441d3000 (   1.064 Gb)  62.82%   53.22%
Heap                                   4070          1b525000 ( 437.145 Mb)  25.20%   21.35%
Free                                   5606          13912000 ( 313.070 Mb)           15.29%
Image                                  1928           b119000 ( 177.098 Mb)  10.21%    8.65%
Stack                                   348           1d00000 (  29.000 Mb)   1.67%    1.42%
Other                                    23            158000 (   1.344 Mb)   0.08%    0.07%
TEB                                     116             74000 ( 464.000 kb)   0.03%    0.02%
PEB                                       1              1000 (   4.000 kb)   0.00%    0.00%

--- Type Summary (for busy) ------ RgnCount ----------- Total Size -------- %ofBusy %ofTotal
MEM_PRIVATE                            5214          5d197000 (   1.455 Gb)  85.86%   72.74%
MEM_IMAGE                              3200           d945000 ( 217.270 Mb)  12.52%   10.61%
MEM_MAPPED                             4925           1c02000 (  28.008 Mb)   1.61%    1.37%

--- State Summary ---------------- RgnCount ----------- Total Size -------- %ofBusy %ofTotal
MEM_RESERVE                            3371          39fe0000 ( 927.875 Mb)  53.48%   45.31%
MEM_COMMIT                             9968          326fe000 ( 806.992 Mb)  46.52%   39.41%
MEM_FREE                               5606          13912000 ( 313.070 Mb)           15.29%

--- Protect Summary (for commit) - RgnCount ----------- Total Size -------- %ofBusy %ofTotal
PAGE_READWRITE                         2965          2399c000 ( 569.609 Mb)  32.83%   27.81%
PAGE_EXECUTE_READ                       459           a357000 ( 163.340 Mb)   9.42%    7.98%
PAGE_READONLY                          6115           3941000 (  57.254 Mb)   3.30%    2.80%
PAGE_WRITECOPY                          153            b12000 (  11.070 Mb)   0.64%    0.54%
PAGE_EXECUTE_READWRITE                  109            3fb000 (   3.980 Mb)   0.23%    0.19%
PAGE_EXECUTE_WRITECOPY                   51            102000 (   1.008 Mb)   0.06%    0.05%
PAGE_READWRITE|PAGE_GUARD               116             bb000 ( 748.000 kb)   0.04%    0.04%

--- Largest Region by Usage ----------- Base Address -------- Region Size ----------
<unknown>                                   46da1000           23ff000 (  35.996 Mb)
Heap                                        6d110000           2b30000 (  43.188 Mb)
Free                                        7c647000             19000 ( 100.000 kb)
Image                                       35a6f000            cc5000 (  12.770 Mb)
Stack                                         f80000             3d000 ( 244.000 kb)
Other                                         3a0000            103000 (   1.012 Mb)
TEB                                         7fec0000              1000 (   4.000 kb)
PEB                                         7ffd3000              1000 (   4.000 kb)

通过!address命令直接查看下内存分布情况,发现内存中全是如下形式
+ 7fce0000 7fce1000     1000 MEM_MAPPED  MEM_COMMIT  PAGE_READONLY                      <unknown> 
+ 7fce1000 7fcf0000     f000             MEM_FREE    PAGE_NOACCESS                      Free      
+ 7fcf0000 7fcf1000     1000 MEM_MAPPED  MEM_COMMIT  PAGE_READONLY                      <unknown> 
+ 7fcf1000 7fd00000     f000             MEM_FREE    PAGE_NOACCESS                      Free      
+ 7fd00000 7fd01000     1000 MEM_MAPPED  MEM_COMMIT  PAGE_READONLY                      <unknown> 
+ 7fd01000 7fd10000     f000             MEM_FREE    PAGE_NOACCESS                      Free      
+ 7fd10000 7fd11000     1000 MEM_MAPPED  MEM_COMMIT  PAGE_READONLY                      <unknown> 
+ 7fd11000 7fd20000     f000             MEM_FREE    PAGE_NOACCESS                      Free      
+ 7fd20000 7fd21000     1000 MEM_MAPPED  MEM_COMMIT  PAGE_READONLY                      <unknown> 
+ 7fd21000 7fd30000     f000             MEM_FREE    PAGE_NOACCESS                      Free      
+ 7fd30000 7fd43000    13000 MEM_PRIVATE MEM_COMMIT  PAGE_READWRITE                     <unknown> 
+ 7fd43000 7fd50000     d000             MEM_FREE    PAGE_NOACCESS                      Free      
+ 7fd50000 7fd51000     1000 MEM_MAPPED  MEM_COMMIT  PAGE_READONLY                      <unknown> 
+ 7fd51000 7fd60000     f000             MEM_FREE    PAGE_NOACCESS                      Free      
+ 7fd60000 7fd61000     1000 MEM_MAPPED  MEM_COMMIT  PAGE_READONLY                      <unknown> 
+ 7fd61000 7fd70000     f000             MEM_FREE    PAGE_NOACCESS                      Free      
+ 7fd70000 7fd71000     1000 MEM_MAPPED  MEM_COMMIT  PAGE_READONLY                      <unknown> 

查看其中内存内容,发现是GIF格式的图片占用了空间
0:000> dc 7fcf0000
7fcf0000  38464947 00786139 00f7001e 7b787200  GIF89ax......rx{
7fcf0010  dff5efe2 e8dcf2ec f3ede0ee d7f4eee1  ................
7fcf0020  aea5e9e4 e4ded2b2 9e918d86 bbb1aca8  ................
7fcf0030  8e8a83c0 9bebe6d9 d0c5a8a4 b1aca3d5  ................
7fcf0040  ddb5b1a7 e8dbefe9 dbd6caed a4c9c4b9  ................
7fcf0050  968eb2ad c8c3b899 c2beb9af c9bfd2cd  ................
7fcf0060  7c7973ce debbb7ad 857ef0ea 9b988f88  .sy|......~.....
7fcf0070  96e7e1d5 9088a39e e8e2d694 8ed4cfc4  ................

通过如下命令查看这种形式的内存使用,居然有4873处,计算一下 (f000+1000) * 4873 = 319356928, 占用了300多MB空间,难怪空闲空间很多,但是连续的又这么少。
0:000> .shell -ci "!address" find /C "1000 MEM_MAPPED  MEM_COMMIT  PAGE_READONLY                      <unknown>" www.2cto.com
4873
.shell: Process exited

一般来说<unknown>内存空间是被managed程序占用,查看一下finalizequeue,发现里面正好有4000多个bitmap
0x7ae3c9f8    4,884      117,216 System.Drawing.Bitmap