从加载了 SOS 调试扩展的 Visual Studio 即时窗口中,我可以做到
!dumpheap -stat
然后我得到这样的东西:
total 108,014 objects
Statistics:
MT Count TotalSize Class Name
...
0x00be209c 135 714108 System.Object[]
0x79b925c8 218 2659728 System.String
0x00be2c3c 78986 10,705,064 System.Byte[]
Total 208,014 objects, Total size: 36,259,364
我现在如何在某些 System.Byte[] 实例上调用 !gcroot ?我首先要找到他们的地址。但是使用 !dumpheap -type System.Byte[] 肯定是个坏主意,因为这会给我一个无穷无尽的列表,而且由于即时窗口似乎很慢,因此需要 20 多分钟才能列出它们——当时 Visual Studio 不是可用。有一个秘密的技巧我可以在某些字节数组上调用 !gcroot 吗?