HighTechTalks DotNet Forums  

Reference type's memory storage size

Dotnet Framework (Performance) microsoft.public.dotnet.framework.performance


Discuss Reference type's memory storage size in the Dotnet Framework (Performance) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Amir Shitrit
 
Posts: n/a

Default Reference type's memory storage size - 03-04-2006 , 07:46 PM






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?
Thanks.

Reply With Quote
  #2  
Old   
Jon Shemitz
 
Posts: n/a

Default Re: Reference type's memory storage size - 03-05-2006 , 01:26 AM






Amir Shitrit 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?).
If you've heard many answers, why should you think that this time
you'll get an answer that you believe?

It's vtable and syncblock, btw.

--

<http://www.midnightbeach.com> Contracting, consulting and training
..NET 2.0 book coming out in June <http://www.midnightbeach.com/.net>


Reply With Quote
  #3  
Old   
Jon Skeet [C# MVP]
 
Posts: n/a

Default Re: Reference type's memory storage size - 03-05-2006 , 03:37 AM



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


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.