What can cause StackOverflowError? Who to avoid/stop StackOverflowError?
What can cause StackOverflowError? Who to avoid/stop StackOverflowError?
StackOverflowError are caused when you make too many nested calls to the same method and are typical in recursive code.
Also it's depends on computer ram and processor. A normal computer can handle 9500 nested method call.
If the computation in a thread requires a larger Java Virtual Machine stack than is permitted, the Java Virtual Machine throws a StackOverflowError.
The stack has a limited size, and consequently can only hold a limited amount of information. If the program tries to put too much information on the stack, stack overflow will result. Stack overflow happens when all the memory in the stack has been allocated — in that case, further allocations begin overflowing into other sections of memory.
....
int a=1;
....
....
getNumber();
}
public void getNumber(){
.........
.........
print();
}
StackOverflowError are caused when you make too many nested calls to the same method and are typical in recursive code.
Also it's depends on computer ram and processor. A normal computer can handle 9500 nested method call.
If the computation in a thread requires a larger Java Virtual Machine stack than is permitted, the Java Virtual Machine throws a StackOverflowError.
The stack has a limited size, and consequently can only hold a limited amount of information. If the program tries to put too much information on the stack, stack overflow will result. Stack overflow happens when all the memory in the stack has been allocated — in that case, further allocations begin overflowing into other sections of memory.
Example:
public void print(){....
int a=1;
....
....
getNumber();
}
public void getNumber(){
.........
.........
print();
}
Comments
Post a Comment