← Software Engineering & Cloud Studio
Concept Explainer · Software Engineering

Stack vs Heap

Where your variables actually live in memory — and why the difference decides whether a bug crashes instantly and obviously, or hides for hours before it does.

Ask most new programmers where a variable "lives" and you'll often hear some version of "in the heap" — as if there's only one place memory comes from. There isn't. Every running program keeps at least two very differently managed regions of memory: a stack, which handles the mundane bookkeeping of function calls with almost no overhead, and a heap, which handles everything whose size or lifetime can't be pinned down at compile time. Mixing up which region a piece of data lives in is one of the most common sources of real bugs in unmanaged languages, and misunderstanding it still causes confusion even in garbage-collected ones.