Stack: stores function call frames and local variables, allocated and freed automatically in last-in-first-out order, very fast, but limited in size (stack overflow from deep recursion or large locals).
Heap: dynamically allocated memory (malloc, new) that lives until freed or garbage collected, flexible in size and lifetime, but slower and subject to fragmentation, leaks and dangling pointers.
Each thread has its own stack, while all threads share the heap.
Loading…