Computer programs are composed of groups of instructions known as subroutines. Subroutines are able to call other subroutines, so you can have subroutine A do some stuff, call subroutine B, and then do some more stuff once subroutine B has finished running.
In order to remember that it needs to finish running the rest of subroutine A after subroutine B is done, computers track subroutine calls in what’s known as the call stack. When subroutine A calls subroutine B, the computer will put some info about how far it had gotten through subroutine A on top of the call stack, and it’ll remove that info when subroutine B finishes running and we go back to subroutine A.
A stack overflow happens when there are too many subroutine calls for the call stack (which has a limited amount of memory) to hold. This usually happens when there’s a bug in the program that allows one or more subroutines to be called infinitely.
Latest Answers