When you instantiate an object, an area of memory on the heap is allocated to store the object’s data. So we typically say that the object is on the heap.
Person thatGuy = new Person("Julius", "Caesar");
In the above example, a new instance of the Person class is created and the data for this Person is stored on the heap.
But in creating a new instance of a Person, we also had to declare and instantiate a reference to the Person object that we just created. That reference is stored on the stack.
In the same way that value types are normally stored on the stack, but can be on the heap if they exist within another object, object references can also be on the heap if they are contained within other objects.
Filed under: Basics Tagged: C#, Heap, Objects, Stack Image may be NSFW.
Clik here to view.

Clik here to view.
