Stack and Heap Primer

By Deane Barker on March 31, 2009

Value vs Reference Types in C#: This is an excellent explanation of the programming concepts of the “stack” and the “heap,” and a comparison of value types and reference types. (And, if you’re a C# programmer, and great explanation of how structs are different from full-blown objects.)

The Common Language Runtime allocates memory for objects in two places: the stack and the heap. The stack is a simple first-in last-out memory structure, and is highly efficient. […]

In contrast, the heap can be pictured as a random jumble of objects. Its advantage is that it allows objects to be allocated or deallocated in a random order. As we’ll see later, the heap requires the overhead of a memory manager and garbage collector to keep things in order.

Some good diagrams that cleared up some confusion for me.

(And why don’t I know this already? Because my B.A. is in Political Science. A side-effect of being an “accidental programmer” is that you don’t learn things until you need them, so sometimes you find yourself learning incredibly remedial things later on in your career. Example: I still don’t know the difference between Base 2 and Base 10.)



  1. There are 10 types of people in the world; those that understand binary and those that don’t.

Comments are closed. If you have something you really want to say, email and we‘ll get it added for you.