A program uses a call stack to keep track of method calls
Java's Call Stack
Call stack
- made up of stack frames
- one stack frame per method call
Stack Frame
- contains info about method & its variables
- local variables, arguments passed into the method, information about caller's stack frame, return address
- return address: what the program should do after the function returns
- where it should return to
- added to the call when execution enters the method
- removed from call stack if execution is done
Stack overflow
When we run out of space
i.e. in a recursive function
Each method call creates its own stack frame and takes up space on the call stack. The space complexity of an algorithm may overwhelm the stack space.
References