Stack Vs Heap Memoy Management

In C# memory management and garbage collection is happen through the CLR. So in many cases memory management and garbage collection is not a responsible of the programmer.but it is good to have a knowledge about how memory management works for apply it to practical scenarios.
as we know in C# value types store in stack and reference types store in heap.let's talk about it with more details.

think stack as a set of boxes put one on top of the next.we can only use the top box on the stack.if we need another we have to take off the boxes one by one until find the relevant box.
but heap is not like the stack.we can access to anything in the heap once without moving others from there positions.so in heap we can find what we need quickly.
the stack always maintain it's memory allocations by it self.so if the top element of the stack is no longer used it's thrown out.

But in heap memory deallocation is done through the garbage collector. GC find all objects in the heap that are no longer accessed by the main program and delete them.

  Stack


  Heap

For more Information:
http://www.c-sharpcorner.com/uploadfile/rmcochran/csharp_memory01122006130034pm/csharp_memory.aspx?articleid=9adb0e3c-b3f6-40b5-98b5-413b6d348b91