Eli5-What does a “stack overflow” mean?

1.22K views

Eli5-What does a “stack overflow” mean?

In: 847

41 Answers

Anonymous 0 Comments

The stack is the space where a computer stores the details of a program that it’s running. Not the data, but which arguments it was given, for example.

One way to make a large program easier to read or maintain is to split it up into small functions that do one thing and pass the result either back to the original program or on to another function.

Each time a function is called, some space is allocated in memory on the stack to reference where the function code is, what input values were passed to it, etc. When a function returns back to the one that called it, those entries are removed from the stack.

Sometimes a bug (or badly written program) will add too many entries for the memory in the computer to handle, and that’s when you get a stack overflow. This can happen due to a function calling a function, etc, without ever ‘returning’, or some error in the logic causing an infinite loop that will never return (usually in recursion).

Hence the stack will ‘overflow’ the amount of space given by the operating system.

You are viewing 1 out of 41 answers, click here to view all answers.