you can use a profile, for example, the COM based profiling API, ICorProfilerInfo::GetObjectSize(), of course, you still need to recursively get the size of all the contained objectsif you class is serializable, you can try something likeMemoryStream ms = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(ms,YourObjectInstance);
Console.WriteLine(ms.ToArray().Length);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(ms,YourObjectInstance);
Console.WriteLine(ms.ToArray().Length);
不过要是能看见那个对象内部的结构和各个地方的占用就爽翻了……
我现在也在搞不懂一个WEB程序里,内存到底分别用到哪了,想看清楚一点,好优化