Caffeinated Coder
Book an appointment
Lesson 23 · How programs really run

The stack and the heap

A running program keeps its memory in two places. The call stack holds one frame per running call: its parameters, its local names and where to go back to. The heap holds the objects themselves, which can outlive the call that made them. Step through a short Python program and watch frames get pushed and popped, names point to objects on the heap, a list survive its function, and memory get freed; then see a stack overflow and how C makes you manage the heap by hand.

11 min9 steps5 questionsIntermediate
Fig 23 · Interactive
Loading figure…
or ← →

Quiz Unlocks after the last step.