GC (Allocation Failure) VS OutOfMemoryError Exception

后端 未结 2 591
栀梦
栀梦 2021-01-05 04:24

\'OutOfMemoryError\': Usually, this error is thrown when there is insufficient space to allocate an object in the Java heap.

GC (Allocation Failure): Allocation Fail

相关标签:
2条回答
  • 2021-01-05 04:58

    These could become related as far as I can tell; but they are entirely different things.

    OutOfMemory is an error you can not recover from - the JVM will die at this point.

    GC (Allocation Failure): Allocation Failure is the reason why GC will kick in (and do a minor collection). At this point some things might happen, like: enough space is freed for the new allocation to fit into young generation. Or that did not happen and some objects will be promoted to the old generation. If they can't be promoted, a full GC might be triggered - and if that does not free enough space an OutOfMemory might be thrown.

    0 讨论(0)
  • 2021-01-05 05:07

    In general, an OutOfMemoryError occurs when you have exceeded the maximum memory you have already allocated to the JVM. This amount can be changed when starting java using jvm parameters. e.g. -Xmx2G. Note that this amount isn't used immediately. See below.

    GC (Allocation Failure) is similar, except it occurs when the garbage collector runs out of memory on the heap, and it attempts to allocate more. If your allocated memory is higher than your available system memory, this will fail. Essentially, the JVM tries to allocate memory which isn't there.

    See for more information

    0 讨论(0)
提交回复
热议问题