Eli5-What does a “stack overflow” mean?

1.20K views

Eli5-What does a “stack overflow” mean?

In: 847

41 Answers

Anonymous 0 Comments

The “stack” is a section of memory reserved for use by a computer’s CPU to temporarily store working data. It’s called a stack because it operates like a stack (of plates, memos, whatever). You can only add data by tossing it on top of the stack, and you can only read data by taking it off the top of the stack.

But the memory allocated to the stack is limited. When an attempt is made to add more data to the stack than it has room for, *voila,* “stack overflow”. This is a critical error and the program stops immediately.

The easiest way to get a stack overflow is for a subroutine to call itself. When a program calls a subroutine, it pushes a return address onto the stack so the subroutine knows where to return to when it’s done. But if it’s calling itself and never returning, those return addresses will pile up infinitely. Without the enforced size limit on the stack, it could grow until it overwrites all memory, crashing the entire computer instead of just the currently running program.

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