Call Stack
Subject: Computer and Technology noun /ˈkɔːl ˌstæk/ 1 definition
- computer-science
- data-structures
- memory-management
- programming-languages
-
Definition (noun)
Entry #116 · UpdatedA Call Stack is a last-in, first-out (LIFO) memory structure used by a program runtime to track active subroutine invocations and coordinate control flow. Whenever a function or method is invoked, the runtime pushes a new stack frame—containing the return address, passed arguments, saved registers, and local variables—onto the top of the stack, and pops that frame when execution returns to the caller. Unlike heap memory, which supports arbitrary allocation lifetimes, the call stack enforces strict nested scoping within a bounded, thread-local memory region; exceeding this fixed capacity triggers a stack overflow error.
Common Forms
Native Thread Call Stack: A contiguous region of virtual memory allocated per operating system thread where machine instructions use hardware stack and frame pointers (such as
RSPandRBPon x86-64) to push and pop call frames directly.Managed Runtime Call Stack: An execution stack maintained by a virtual machine or interpreter (such as the JVM or CPython) that tracks bytecode frame descriptors, operand values, and lexical bindings alongside or independently of native frames.
Segmented and Growable Call Stack: A dynamic stack design—used by runtimes such as Go—that starts with a small initial allocation and resizes or links additional stack segments on demand as call depth increases.
Shadow Call Stack: A security-hardened auxiliary stack stored in an isolated memory region that duplicates function return addresses so the runtime can detect and block stack buffer overflows or return-oriented programming attacks.
Example
When a Python web service handles a request in
handle_checkout(), which invokescalculate_tax(cart)and thenfetch_rate(zip_code), the interpreter pushes three sequential stack frames holding each function's local variables and return addresses. Asfetch_ratefinishes, its frame is popped off the top to resumecalculate_tax, or—if an unhandled error occurs—the runtime walks the remaining stacked frames from top to bottom to print a diagnostic traceback.