不匹配的对象大小返回sos.dll和内存中的进程大小大小、不匹配、进程、对象

由网友(女人就该有国际范)分享简介:我已经使用以下命令SOS枚举特定类型的运行ASP应用程序的所有实例(托管在Windows XP的4 GB机)。I have used the following sos command to enumerate all instances of a particular type in a running asp a...

我已经使用以下命令SOS枚举特定类型的运行ASP应用程序的所有实例(托管在Windows XP的4 GB机)。

I have used the following sos command to enumerate all instances of a particular type in a running asp application (hosted on windows xp 4 GB machine).

.foreach (obj { !dumpheap -type ::my type:: -short ::start of address space:: ::end of address space:: }) { !objsize ${obj} }.

此枚举给定类型的GC第二代的所有对象。

This enumerates all objects of the given type in gc gen2.

上的平均的对象的大小似乎是大约500 KB和有大约2000的对象。仅这一点就增加了约1 GB的内存,而我的任务管理器ASP-进程内存显示只有大约700 MB。还有一个问题是,我还没有考虑过我是用其它加载的对象。

The object size on an average seems to be around 500 KB and there are around 2000 objects. This alone adds up to around 1 GB of memory whereas my asp-process memory in task manager shows only around 700 MB. One more point is that I haven't considered other loaded objects I am using.

此外上述所有对象都不会被垃圾回收根对象。不知道这命令是错误的,或者有其他解释这种不匹配的大小SOS儿童村的回报,什么是显示在任务管理器?

Also all the above objects are root objects that will not be garbage collected. Not sure if this command is wrong or if there is any other explanation for this mismatch in size that sos returns and what is shown in task manager?

在前进,谢谢 Bharathķ。

Thanks in advance, Bharath K.

推荐答案

!objsize 计算实例包括它的所有引用的对象的大小,因此,如果您有任何对象这一比例对其他对象的这些大小将被计算多次。这样做的最常见的来源可能是字符串,文字字符串被拘留,因此使用相同的文字文本对象共享。但是,你也可以有收藏引用同一个对象。在任何情况下,总和将是不正确的,除非计算对象在所有不共享任何引用。

!objsize calculates the size of an instance including all its referenced objects, so if you have any objects that share references to other objects the size of these will be counted multiple times. The most common source for this is probably strings, as literal strings are interned and thus shared among objects using the same literal text. However, you may also have collections referencing the same objects. In any case, the sum will be incorrect unless the counted objects do not share any references at all.

考虑这个例子

class SomeType {
    private readonly string Text;

    public SomeType(string text) {
        Text = text;
    }
}

这code

and this code

var st1 = new SomeType("this is a long string that will be stored only once due to interning");
var st2 = new SomeType("this is a long string that will be stored only once due to interning");

在WinDbg中

0:006> !dumpheap -type Some
 Address       MT     Size
00ceb44c 00b738a8       12     
00ceb458 00b738a8       12     

0:006> !objsize 00ceb44c
sizeof(00ceb44c) =          164 (        0xa4) bytes (TestApp.SomeType)
0:006> !objsize 00ceb458
sizeof(00ceb458) =          164 (        0xa4) bytes (TestApp.SomeType)

0:006> !DumpObj 00ceb44c
Name:        TestApp.SomeType
MethodTable: 00b738a8
EEClass:     00b714bc
Size:        12(0xc) bytes
File:        c:dev2010FSharpLibTestAppbinReleaseTestApp.exe
Fields:
      MT    Field   Offset                 Type VT     Attr    Value Name
79b9d2b8  4000001        4        System.String  0 instance 00ceb390 Text
0:006> !DumpObj 00ceb458
Name:        TestApp.SomeType
MethodTable: 00b738a8
EEClass:     00b714bc
Size:        12(0xc) bytes
File:        c:dev2010FSharpLibTestAppbinReleaseTestApp.exe
Fields:
      MT    Field   Offset                 Type VT     Attr    Value Name
79b9d2b8  4000001        4        System.String  0 instance 00ceb390 Text

正如你可以从的输出看!dumpobj ,他们都共享同一个参考,所以,如果你总结的大小所报告的! objsize 上方,该字符串计算两次。

As you can see from the output of !dumpobj, they both share the same reference, so if you sum the size as reported by !objsize above, the string is counted twice.

阅读全文

相关推荐

最新文章