I have a static object at runtime that is basically a list of other objects (ints, strings, Dictionary, other objects, etc). Is there way to determine the memory used by my static "list of other objects" object at runtime? This would be handy for instrumentation and reporting purposes.
Sizeof can be used on value types there is also Marshal.SizeOf which can be used with some hints to .NET:
http://www.pixelicious.net/2008/07/03/exception-trying-to-get-the-size-of-a-c-class-using-marshalsizeof
But... that isn't exactly the total cost since the runtime does allocate extra bytes for classes for things like sync blocks.
If you are really interested in measuring this type of thing, however, you should use the profiling API:
http://msdn.microsoft.com/en-us/library/ms404386.aspx
Or a free tool like windbg that can do all sorts of wonderful things.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With