Glossary

Heap, Stack and Memory

Stack and Heap are two memory regions used by programs in different ways. Understanding them helps diagnose memory leaks and stack overflows.

Stack (call stack)

Automatically managed memory for local variables and call frames. When a function is called, its data is pushed onto the stack. On return — it is popped. Stack overflow = recursion too deep, stack exhausted.

Heap

Dynamic memory for objects with an indefinite lifetime. Allocated on new Object(), freed by the garbage collector. Memory leak = objects are not freed because "stray" references to them exist.

In PHP