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

The Java Machine Specification states in section 6.3 (emphasis mine):

OutOfMemoryError: The Java virtual machine implementation has run out of
either virtual or physical memory, and the automatic storage manager was unable
to reclaim enough memory
to satisfy an object creation request.

So the JVM does give a guarantee that it will try what it can to free up memory through garbage collection before it throws an OOME.

Leave a Comment