Conceptual
Login

Stack and Heap Memory

The stack allocates and frees automatically in LIFO order with each function call and is fast but fixed-size per frame; the heap serves arbitrary-lifetime, arbitrary-size allocations that something must explicitly free. Where a value lives determines who is responsible for reclaiming it.

Questions this Concept answers

  • Why must a value whose size is not known until runtime live on the heap rather than the stack?