Is the garbage collector guaranteed to run before Out of Memory Error?

后端 未结 5 1213
清酒与你
清酒与你 2020-12-01 21:12

In case the heap is full, the JVM throws an OutOfMemoryError. But is it assured that a (full) garbage collection always takes place before such an exception is thrown?

5条回答
  •  执念已碎
    2020-12-01 21:23

    There's no guaranty that the last operation preceding OutOfMemoryError is garbage collection. Most probably not, since garbage collection would reduce the amount of used memory not increase it.

提交回复
热议问题