What's the difference between StackOverflowError and OutOfMemoryError

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

    From Javadocs: Exceptional conditions associated with JVM Stacks:

    1) if insufficient memory can be made available to create the initial JVM stack for a new thread, the JVM throws an OutOfMemoryError.

    2) If the computation in a thread requires a larger JVM stack than is permitted, the JVM throws a StackOverflowError.

    3) If JVM stack can be dynamically expanded, and expansion is attempted but insufficient memory can be made available to effect the expansion, the JVM throws an OutOfMemoryError.

    Exceptional conditions associated with Heap:

    1) If a computation requires more heap than can be made available by the automatic storage management system, the JVM throws an OutOfMemoryError.

提交回复
热议问题