Amir Shitrit <AmirShitrit (AT) discussions (DOT) microsoft.com> wrote:
Quote:
I know this question has been asked many times, but Iv'e heared many answers
for this question, so I don't know what to believe.
How much memory does a reference type occupies in the manged heap?
Some say 4 bytes only (for the virtual table, or Type instance reference)
and some say 8 bytes (vtable + SynchBlock?).
So, which is it? |
8. The easiest way to check this is to check used memory, create a
million object instances (keeping a reference to them, eg in an array),
then check used memory again (with GC.GetTotalMemory). It's not
entirely reliable - things like writing out the initial memory will
force the Console class to load, adding to the total memory etc) but if
you create enough objects the trend is very obvious.
--
Jon Skeet - <skeet (AT) pobox (DOT) com>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too