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?
This would mean that the memory is full only with strong referenced objects (or reachable by GC Roots) when the exception is thrown.
Edit: Assume the Sun JVM – HotSpot is in discussion.
The Java Machine Specification states in section 6.3 (emphasis mine):
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.