A quick overview of the call stack in computer science.
In computer science, the call stack, also known as the execution stack, program stack, control stack, runtime stack or machine stack is a dynamic data structure which stores information in memory about the active subroutines of a computer program.
“The stack” as it’s more commonly referred to, is a “last in, first out” data structure. Meaning that the last function call added to the stack will be the next to be removed after the function returns.
To better understand how this works we need to know some key terminology when talking about the call stack.
The active frame is the function at the top of the call stack currently being executed.
When a new frame is pushed onto the call stack, memory is allocated and it becomes the new active frame.
When a function has returned it is popped off of the call stack and the function immediately below it becomes the new active frame.
Understanding the call stack is often helpful when debugging.
You might be wondering if there are any limits to how many stack frames can be on the call stack at one time. The answer varies depending on several factors such as the operating system, language, compiler and browser (Javascript).
Here are some methods to find the call stack limit; I will demonstrate this in Javascript and Python.
The information stored by a stack frame includes the function in which was invoked, the parameters passed to the function and the current line number.
Resources:
https://en.wikipedia.org/wiki/Call_stack#:~:text=In%20computer%20science%2C%20a%20call,to%20just%2 0%22the%20stack%22.
https://stackoverflow.com/questions/7826992/browser-javascript-stack-size-limit
https://stackoverflow.com/questions/3323001/what-is-the-maximum-recursion-depth-in-python-and-how- to-increase-it