Search code examples
c#.netmemory-managementdynamic-memory-allocationmanaged

Memory allocation for variable declared in class


As Value type variable allocates memory in Stack whereas Reference type allocates it in Heap.

So how the memory allocated when a value type variable (e.g. int i = 4;) is declared in the reference type (e.g. in a class).

How the overall memory allocation works in .NET for value type & reference type, and also value type inside the scope of reference type.

Please explain it or provide any links regarding that.


Solution

  • So how the memory allocated when a value type variable(eg int i =4;) is declared in the reference type (eg. in a class).

    If the object lies on heap, it means all it's member variable(s) lies there.