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.

Example:

public void print(){
....
int a=1;
....
....
getNumber();
}

public void getNumber(){
.........
.........
print();
}

Who to avoid/stop StackOverflowError?

Reduce too many nested method calls in your program.


Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)