This is true, but the presence of code turns out to be irrelevant. An
object with no data AND no code will also consume memory.  Exactly the
same amount of memory will be consumed in either case.

The type header pointer is the same size for all objects - it's just a
pointer!  And the sync block index is also the same size for all
objects.  These are present whether you have code or not.

There is nothing in an object instance that gets larger in proportion to
how much code there is in that object's class.


-- 
Ian Griffiths
DevelopMentor

-----Original Message-----
From: Ivan Towlson

Every object carries around a vtable pointer (because System.Object has
virtual functions) and a sync block index.  So yes, instantiating even
an
object with no data will consume memory.

-----Original Message-----
From: Craig Boland

Does anyone know what factors affect the memory size an object will
consume by simply creating a new instance? I know that member-level
value-
types will consume memory respective of their data type (Int32 consumes
4
bytes, etc.). What about code? Does a class that contains no member
variables, but 2000 lines of code consume any memory by simply
instantiating a new one?

Reply via email to