What happens when the JVM runs out of memory to allocate during run time?

前端 未结 5 1805
难免孤独
难免孤独 2020-12-15 05:37

After thinking for a long time of a generic way to pose this question (and failing to find one) I\'m just going to ask it as a concrete example:

Suppose I have a Lin

5条回答
  •  隐瞒了意图╮
    2020-12-15 06:20

    The JVM process will run in virtual memory, so the question of allocation of other processes running is relevant, but not completely determinitive.

    When the JVM cannot allocate more memory (for whatever reason), the process itself doesn't terminate, but rather starts throwing OutOfMemoryError within the JVM, but not external to the JVM. In other words, the JVM continues to run, but the programs running within the JVM will usually fail, because most don't handle low memory conditions adequately. In this fairly common case, when the program does not do anything to handle the error, the JVM will terminate the program and exit. Ultimately, this is from the memory allocation, but not directly so. It's possible for a piece of code to scale itself back under low memory condition and continue to run.

    And others have pointed out, it happens sometimes that the JVM itself doesn't handle low memory well, but this is a pretty extreme condition.

提交回复
热议问题