Saturday, October 13, 2007

Heap vs Stack

C# Heap(ing) Vs Stack(ing) in .NET


  • The Stack is responsible for keeping track of what's executing in our code (or what's been "called"). So we can only use what's in the top box on the stack.
  • Self-maintaining, when top-box is no longer used, it's thrown out.
  • Value Types and Pointers always go where they were declared. If a Value Type is declared outside of a method, but inside a Reference Type it will be placed within the Reference Type on the Heap.


  • The Heap's purpose is to hold information (not keep track of execution most of the time) so anything in our Heap can be accessed at any time.
  • The Heap has to worry about Garbage collection (GC) - which deals with how to keep the Heap clean
  • A Reference Type always goes on the Heap

blog comments powered by Disqus