location of storage of instance fields of reference type objects

i had a doubt, suppose in my class (say containing class) i have a field instance which is an object of reference type (say another class as example, call it inner class), at run time when the object of containing class is created on the heap, does containing class stores the entire inner class object in it, or containing class stores the reference of the inner class in it ?

    internal class ContaingClass
    {
       private InnerClass objInner; 
    }

would object of ContainingClass have reference of objInner or shall store entire objInner with all it's data in it?


When InnerClass is a reference type it's stored as a refence to the instance.

Here is an answer from Eric Lippert that explains the details on what happens during execution.


Upon construction it would contain a null reference in the field (assuming your constructor doesn't set it to anything). The field could later be assigned to a reference to an instance, but the 'contents' of that instance would not be stored inside the ContainingClass 'contents'.

链接地址: http://www.djcxy.com/p/82596.html

上一篇: 内存结构用于参考和值类型

下一篇: 存储引用类型对象的实例字段的位置