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, 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
ha, your english is a bit hard to understand, but i think i get what your asking.
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.
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.
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.