Eli5-What does a “stack overflow” mean?

1.19K views

Eli5-What does a “stack overflow” mean?

In: 847

41 Answers

Anonymous 0 Comments

Computers use RAM to store memory, like your brain stores active thoughts or a bucket stores water. Stack overflow happens when you try to remember too many things at once or put too much water in a bucket.

Anonymous 0 Comments

Imagine you’re a computer, and your job is to count to 1000. However, while you’re in the midst of counting, I might interrupt you and ask you to recite the alphabet. When you’re done with the alphabet, you should continue where you left off with the counting.

In order to continue where you left off with the counting, you need to store which number you were on when you were interrupted. Let’s say you do this by writing it down on a slip of paper.

Now, imagine things get more complex. While you’re reciting the alphabet, I might interrupt you again and ask you to list all the states in the US in alphabetical order. And while you’re listing the states, I might interrupt you again and ask you to list all the planets in the solar system in order from their distance to the Sun. And so on.

Each time I interrupt you, you have to do as I ask, and when you finish a task, you need to go back to the previous task you were doing and finish that, and then the task before that, etc.

Each time you’re interrupted, you need to store the last thing you were doing before you were interrupted, so that you can resume it later. Since I might interrupt you multiple times, it would be convenient to put those slips of paper in a stack. That way, when you finish a task, you can take the top slip of paper and remember where you left off on that task.

Now, imagine that you only have 5 slips of paper to write things down on. If I interrupted you a 6th time, you’d run out of paper and wouldn’t be able to remember where you left off on the last task. Since you wouldn’t be able to add another slip of paper to the stack, you’d be in a stack overflow.

Anonymous 0 Comments

A stack-overflow error is a CPU/OS reported error that a program has tried to allocate too much memory, which is why the OS stops the program from running.

The stack is a structure used by programs to store dynamic data on, mainly to manage data allocation for sub-routines. A program that goes into an infinitive loop calling a sub-routine but never returns, will eventually run out of stack space.

The TL;DR “Stack overflow” -> “out of memory”. Computers have a lot of different kinds of memory which can be confusing.

Anonymous 0 Comments

In ELI5 terms? Get a friend. Say a number. They double it. You double it. Repeat. Eventually you forget what the earlier numbers were. In a stack, all the numbers are important. If you can’t remember them all, you overflowed your ability to remember them. You got a stack overflow.

Anonymous 0 Comments

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.

Anonymous 0 Comments

Aside from the actual answers already provided, if you stumble through /r/ProgrammingHumor, Stack Overflow can also refer to the popular technical question and answer website of the same name.

Anonymous 0 Comments

Imagine you’re running the Space Mountain ride at Disneyland. And the car pulls up, and 8 people get into the car, and it zips off through the tightly-controlled tracks and everyone has a totally normal ride. All good. But then the next car pulls up, and 9 people get on the car. There’s only room for 8 in the car, and the 9th person who doesn’t fit … now works for Disneyland and can do whatever they want.

Anonymous 0 Comments

On top of the answers everyone else made, it’s the website that programmers go to in order to find solutions for problems they aren’t being paid enough to deal with/don’t have time for

Anonymous 0 Comments

There’s no way to meaningfully ELI5 this beyond saying it’s a technical problem with how computers work.

Anonymous 0 Comments

You’re reading a Choose Your Own Adventure book e.g. “To call a taxi, turn to page 23. To take the bus, turn to page 34”.

You only have five bookmarks labeled #1 through #5.

You want to read every possible outcome.

Your plan: Every time you reach a choice, you place the next bookmark, starting with #1. When you reach a dead end, you go back to the last bookmark you placed. When all the options are exhausted, you remove the bookmark.

As you’re reading, you reach a choice, and you realize you have no more bookmarks left. What if you decided to continue writing page numbers on a piece of paper you found? Uh oh, you accidentally wrote over your homework and now you’ll fail the class.

The book is like a computer program. Every choice in the book is called a “call” or “jump”. The bookmarks are called a “call stack.” You might be saying: “The bookmarks don’t look like a stack.” It doesn’t have to. All that matters is the last item placed is the first item removed. This is called “Last In, First Out” (LIFO). If you chose to use another piece of paper, that’s called a “stack overflow.” But you run the risk of clobbering data used for something else.

Instead, you ask for help. So you yell, “Mom, I need more bookmarks!”

Your mom is the operating system. When you yelled, you raised what is called a “stack overflow exception”, which means you can’t continue.

You hope that your mom simply gives you more bookmarks. Unfortunately, like most operating systems, she throws your book away and tells you to clean your room.