What\'s the difference between StackOverflowError and OutOfMemoryError and how to avoid them in application?
In Java Virtual Machine there are several memory area defined :
In all above, you can choose your precision that memory allocated to those memory area will be fixed or will be changed dynamically at runtime.
Now about the question, OutOfMemoryError is applicable for all of the above listed. OutOfMemoryError
will be thrown if memory expansion of any of the memory area will be attempted but enough memory is not available to allocate.
and StackOverFlowError is applicable for Native Method Stack and Java Virtual Machine Stack. StackOverFlowError
will be thrown If the computation in a thread requires a larger stack than is permitted.
For Detailed reference you can read THE STRUCTURE OF THE JAVA VIRTUAL MACHINE