What's the difference between StackOverflowError and OutOfMemoryError

后端 未结 11 1477
不知归路
不知归路 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:42

    StackOverflowError happens when you execute too many methods one inside another (for example with an infinite recursion), which is limited by the size of the stack.

    OutOfMemoryError happens when the JVM runs out of space to allocate new objects, which are allocated on the heap.

提交回复
热议问题