什么是要找出多少内存的对象使用.NET中最简单的方法是什么?
What is the easiest way to find out how much memory an object uses in .NET?
preferably,而无需求助于第三方工具。 Marshal.SizeOf或sizeof操作符看起来很有用,但只工作,一个类型的限制范围内。
Preferably without having to resort to a third party tool. Marshal.SizeOf or the sizeof operator look useful but only work with a restricted range of types.
一些相关的帖子:
对象在.NET 内存分析 是否在.NET空数组的任何空间? Object Memory Analysis in .NET Does an empty array in .NET use any space?你也可以做这样的事情:
you could also do something like this:
int startMem = GC.GetTotalMemory(true);
YourClass c = new YourClass();
int endMem = GC.GetTotalMemory(true);
int usedMeme = endMem - startMem;