!objsize
计算,包括其所有引用的对象实例的大小,所以如果你有共享引用到其他对象的任何对象的这些大小将被计入多个倍。最常见的来源可能是字符串,因为文字字符串被实施,因此使用相同的文本文本在对象之间共享。但是,您也可能拥有引用相同对象的集合。在任何情况下,除非所计算的对象根本不共享任何参考,否则总和将不正确。
考虑这个例子
class SomeType {
private readonly string Text;
public SomeType(string text) {
Text = text;
}
}
和验证码
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:\dev2010\FSharpLib\TestApp\bin\Release\TestApp.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:\dev2010\FSharpLib\TestApp\bin\Release\TestApp.exe
Fields:
MT Field Offset Type VT Attr Value Name
79b9d2b8 4000001 4 System.String 0 instance 00ceb390 Text
正如你可以从!dumpobj
输出看到的,他们都有着相同的参考,所以如果你按上面!objsize
报告的大小求和,字符串就是c安装了两次。
你在任务管理器中查看什么计数器? – 2010-02-23 07:53:50
Btw'!dh'显示指定图像的标题。我假设你的意思是'!dumpheap'。 – 2010-02-23 08:08:07
是的。它是!dumpheap。我在任务管理器中查看了内存使用情况和内存使用情况峰值。 – 2010-02-23 08:18:00