What's the difference between StackOverflowError and OutOfMemoryError

后端 未结 11 1501
不知归路
不知归路 2020-12-04 09:07

What\'s the difference between StackOverflowError and OutOfMemoryError and how to avoid them in application?

11条回答
  •  无人及你
    2020-12-04 09:46

    There are two(2) areas in memory the heap and stack.

    1. stack memory is used to store local variables and function call.
    2. heap memory is used to store objects in Java

    If there is no memory left in stack for storing function call or local variable, JVM will throw java.lang.StackOverFlowError,

    while if there is no more heap space for creating object, JVM will throw java.lang.OutOfMemoryError:

提交回复
热议问题