GC (Allocation Failure) VS OutOfMemoryError Exception

夙愿已清 提交于 2020-05-08 03:07:38

问题


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

GC (Allocation Failure): Allocation Failure” means that there is an allocation request that is bigger than the available space in young generation.

Does this mean Allocation Failure will be thrown when Young generation memory is full (Minor GC) and "OutOfMemoryError" is thrown in full GC?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/43862031/gc-allocation-failure-vs-outofmemoryerror-exception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!