What is a stack overflow?

what is a stack overflow error
what is stack overflow in python
what is stack overflow in c
how to check stack overflow in c
stack overflow error python
recursion stack overflow
stack overflow error c++
stack overflow example

What is a stack overflow error? What type of programs/programming languages is it likely to occur in? Is it unlikely to occur in web application code?


From Wikipedia:

In software, a stack overflow occurs when too much memory is used on the call stack. In many programming languages, the call stack contains a limited amount of memory, usually determined at the start of the program.

The stack is a data structure that keeps record of the point the subroutines of a program should return control to when they finish executing. The return addresses are pushed in the stack as the subroutines are being invoked, when the subroutine finish its execution the return address is pulled from the stack. If there are many subroutines and there is no space in the stack a stack overflow happens.

Also in the stack is intended to store local variables so if a local variable is too large is more probable the stack doesn't have space to store it, if this is the case a stack overflow happens too.

Wikipedia includes a nice diagram picturing the stack when a DrawLine subroutine is called from another subroutine called DrawSquare, I hope this picture helps to understand better the stack structure.

There are two main causes of a stack overflow: deep function recursions and excessively large stack variables. Since these are common terms in almost all programming languages a stack overflow can happen besides the complexity of the language.

Guffa contribution: The stack doesn't have anything to do with garbage collection. Modern applications have a larger stack, which makes it slightly less likely to get a stack overflow, but other than that there is no difference.

What is stack overflow?, Stack. A stack, in this context, is the last in, first out buffer you place data while your program runs. Last in, first out (LIFO) means that the last� A stack overflow is an undesirable condition in which a particular computer program tries to use more memory space than the call stack has available. In programming, the call stack is a buffer that stores requests that need to be handled. The size of a call stack depends on various factors. It is usually defined at the start of a program.


The stack contains a number of stack frames and is stored in memory. Every time a function is called, a new stack frame is added to the stack. A stack frame contains the arguments to be passed to the function being called, and the return address, so that when the called function has finished the cpu knows where to return to so it can continue executing the calling function. The stack frame may also contain memory to be used by local variables of the function being called.

In this example, the Main function called WriteCustomerDetails and that called PrintToConsole to write out individual bits of data that the WriteCustomerDetails function looked up:

'=======top of stack=====================' Function: PrintToConsole Arg: John Smith, 34 Acacia Avenue, Age 23 '-----------------------------------------------------------' Function: WriteCustomerDetails Arg: John Smith '-----------------------------------------------------------' Function: Main '======bottom of stack==================='

A stack overflow occurs if enough space for the stack was not reserved. Usually a stack sits in one large contiguous block of memory, so isn't divided into chunks, this means one big piece of memory is needed for it, and this makes it hard for the runtime to try and grow the space reserved for the stack if it fills up.

A stack-overflow can often occur when a function is accidentally written that calls itself. Sometimes it's ok for a function to call itself as long as there is an 'if' or some condition in the function that stops the calls at some point. This is called a recursive function. But, if there is no stopping and the function keeps calling itself, or maybe two or more functions keep calling each other, then very quickly they will eat all of the stack memory up. When there's none left, you get a stack-overflow and the program crashes.

It is possible for this to happen in any program, they don't necessarily have to be complex, and it can happen in code running a website. And, it can occur in scripting languages too.

How does a "stack overflow" occur and how do you prevent it , Stack Overflow is the largest, most trusted online community for developers to learn, share their programming knowledge, and build their careers. Stack Overflow is the largest, most trusted online community for developers to learn, share their programming knowledge, and build their careers.


A stack overflow happens when you use too much stack space. There is generally two situations when this happens:

The first is when you have an error in the code, causing a recursive loop without an exit. For example a property reading from itself:

public int Length {
   get {
      return Length;
   }
}

The second is when you have a recursive loop that is too deep. As the stack space is limited, you can only nest an algorithm a certain number of times. If your algorithm is nested too deep so that it runs out of stack space before it exists, you get a stack overflow. Example:

public bool Odd(int value) {
   if (value == 0) {
      return false;
   } else {
      return !Odd(value - 1);
   }
}

If you call this method with a too large value, it will nest too deep and cause a stack overflow.

Stack Overflow, Translation: There is a limited amount of memory (the call stack) allocated to a program. When that is exceeded (when it overflows), we call it a� Stack Overflow is a question and answer site for professional and enthusiast programmers. It is a privately held website, the flagship site of the Stack Exchange Network, created in 2008 by Jeff Atwood and Joel Spolsky. It features questions and answers on a wide range of topics in computer programming. It was created to be a more open alternative to earlier question and answer sites such as Experts-Exchange. The name for the website was chosen by voting in April 2008 by readers of Coding Horror


From wikipedia, of couse:

In software, a stack overflow occurs when too much memory is used on the call stack. In many programming languages, the call stack contains a limited amount of memory, usually determined at the start of the program. The size of the call stack depends on many factors, including the programming language, machine architecture, multi-threading, and amount of available memory. When too much memory is used on the call stack the stack is said to overflow; typically resulting in a program crash.1 This class of software bug is usually caused by one of two types of programming errors

What the Heck is a Stack Overflow | by Chris I., Definition - What does Stack Overflow mean? A stack overflow is a runtime error that happens when a program runs out of memory in the call stack. The stack� A stack overflow error can occur in a computer program due to excessive memory usage. This excessive memory usage occurs on the call stack, which is where information is stored relating to the active subroutines in the program. The call stack has a limited amount of memory available to it.


A stack overflow occurs when you are using a stack (duh...) and there is a memory allocation/reading problem. in "web programs", as you put it (I assume you are talking about HTML, PHP, JS), either you don't use stacks or the language used does not allow for low level memory control which prevents these problems.

What is a Stack Overflow?, There are two cases in which stack overflow can occur: If we declare large number of local variables or declare an array or matrix or any higher dimensional array� Stack Overflow for Teams, the company’s private paid service, is pitched as a “home base for mission-critical knowledge” designed to assist companies in managing development internally with


Heap overflow and Stack overflow, Stack overflow happens when we try to push one more item onto our stack than it can actually Duration: 5:48 Posted: May 18, 2017 A stack overflow is when you've used up more memory for the stack than your program was supposed to use.


What Is Stack Overflow? - Errors, Exceptions & Causes, Stack Overflow is intended to be an inclusive place where every So they thank the poster… only to be told that on Stack Overflow, “please”� Stack Overflow’s other revenue streams, including advertising from its public questions-and-answers site and the Teams business, have fared better in the wake of the spread of the coronavirus


Stack Overflow Isn't Very Welcoming. It's Time for That to Change , A stack overflow error can occur in a computer program due to excessive memory usage. This excessive memory usage occurs on the call� A stack overflow is an error that user-mode threads can encounter. There are three possible causes for this error: A thread uses the entire stack reserved for it. This is often caused by infinite recursion.