From javadoc:
Unlike soft and weak references, phantom references are not automatically cleared by the garbage collector as they are enqueued. An object that is reachable via phantom references will remain so until all such references are cleared or themselves become unreachable.
Once put into ReferenceQueue, the phantom link's referent object is presumed to be "dead", it's inaccessible in any way by programmer's code. So why JVM waits for a manual clear()? For weak refs it doesn't.
In his answer to a related question about the behavior of a
PhantomReferencewhen the queue is given asnull, Holger says this:In summary:
However you asked your question like this:
Strictly speaking, the JVM waits for either a manual clear, or for the
PhantomReferenceitself to become unreachable. (As Holger said above.)So it is not quite as bad (in Java 8 and earlier) as your question would imply.