I was recently working on an application loading a big object using a custom formatter. A simple question came up: how big is this object in memory? It is clear that sizeof does not work. What are the alternatives?
The first one is to use Visual Studio 2008 Profiler and see how big are every object of the application. Since my application is pretty big, it could take long time before I have the full profile. I needed a simpler and faster way to measure the memory of that single object.
What about WinDbg and SOS extensions? I verified the symbols path were set in my Visual Studio environment and set a breakpoint at the line the object were created. Then from the immediate window I loaded SOS extensions and started looking at the statistics of all objects loaded in the managed heap:
The output of the above command provides the list of managed objects without considering the the inner objects. But that list provides also the methods table from which I can get the addess of the object I am interested on:
!dumpheap -mt 0x...
Finally I can get the real size of the object: