call stack
The region of memory where a running program keeps one frame for each function call that has started but not yet returned.
In more detail
Calling a function pushes a frame holding its local variables and where to resume; returning pops it. Recursion depth equals the number of frames stacked up, and recursion that goes too deep runs out of room and fails with a stack overflow or recursion error. An error that nothing catches unwinds the stack, and the stack trace shows the frames it passed through.
Examples
In the browser: Synchronous code runs entirely on the call stack. The event loop only starts the next microtask or task once the stack is empty, which is why a promise callback always runs after the current code finishes.In JavaScript, microtasks and then event loop callbacks run only when the call stack is empty; an error that reaches the bottom uncaught becomes a Node.js uncaughtException.A Python traceback lists the call stack oldest first, most recent call last.Fiber moves React rendering off the call stack into its own linked structure so the work can pause between units.Related terms
- stack frame — The block of memory for one function call on the call stack, holding that call's local variables and return point.
- recursion — A technique where a function solves a problem by calling itself on a smaller version of the same problem.
- RecursionError — The Python exception raised when recursion goes deeper than the interpreter's limit, which is 1,000 frames by default.
- stack — A collection where the last item added is the first one removed, like a pile of plates.
- thread — A path of execution inside a process that the operating system schedules on a processor; one process can have many.
- stack trace — The list of function calls that were running when an error happened, printed to help a developer find where it came from; Python calls it a traceback.
- event loop — The central loop of an asynchronous program that waits for events, such as timers firing or data arriving, and runs the matching callbacks.
- microtask — A small job, such as a promise callback, that runs as soon as the current piece of JavaScript finishes, before the event loop handles anything else.
- synchronous — Code that runs step by step and makes the program wait for each step to finish before the next one starts.
- uncaughtException — The Node.js process event emitted when an error is thrown and nothing catches it; by default the process prints the stack trace and exits with code 1.
- traceback — The report Python prints when an unhandled exception stops a program, listing the chain of calls that led there and ending with the error.
- Fiber — The internal object React keeps for each component instance, and the name of the React 16+ engine built on those objects.
- Stack Reconciler — The reconciler used before React 16, which processed the whole component tree in one recursive pass that could not be paused.
Taught in
- Space, In-Place Work And The Call Stack — Algorithms & Data Structures for Working Engineers
- Stacks And Queues: Last In Or First In — Algorithms & Data Structures for Working Engineers
- Depth-First Search, Cycles And Topological Order — Algorithms & Data Structures for Working Engineers
- Dynamic Programming: Memoisation And Tabulation — Algorithms & Data Structures for Working Engineers
- Async and Await: Managing Concurrency — Modern .NET Core, C# & Enterprise Microservices
- The Browser Event Loop: Call Stack, Microtasks And Macrotasks — Frontend Architecture & Web Platform
- Node.js Process Architecture: Memory & Heap Spaces — Node.js Internals & Backend Services
- Microtask Queues: process.nextTick vs Promise Timing — Node.js Internals & Backend Services
- Global Error Trapping: uncaughtException & Exits — Node.js Internals & Backend Services
- Reading Error Messages — Hands-on Python: Complete Video Course & Book
- Reading A Traceback Like A Professional — Hands-on Python: Complete Video Course & Book
- React Fiber Architecture: Work Units, Priority And Commits — React 19 & Modern Component Architecture
- Functions And Exceptions Sprint — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
References
- Python sys.getrecursionlimit
- Python inspect: the interpreter stack
- Threads and threading
- MDN glossary: Call stack
- Python tutorial: errors and exceptions