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

后端 未结 5 1147
清酒与你
清酒与你 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:28

    There are other additional factors to consider besides what people have already answered, for example the garbage collection policy you are using. Consider the throughput garbage collection, this will throw an out of memory exception if too much time is being spent collecting and not enough memory is being freed (although the recent changes might have changed things). Having said all this I would not assume garbage collection occurs at any time within the execution of an application that I'm writing...

提交回复
热议问题