Let's say there are two objects: A and B , and there is a pointer Ax --> B , and we create, say, WeakReference , for both A and B , with the associated ReferenceQueue .
Suppose that both A and B become inaccessible. Intuitively, B cannot be considered unreachable to A In this case, we somehow get a guarantee that the corresponding links will be exposed in the intuitive (topological, if there are no cycles) order in the ReferenceQueue ? That is, ref (A) before ref (B). I donβt know - what if the GC marked a bunch of objects as unreachable, and then out of turn in their absence?
I looked at Finalizer.java from guava, seeing this snippet:
private void cleanUp(Reference<?> reference) throws ShutDown { ... if (reference == frqReference) { throw new ShutDown(); }
frqReference is a PhantomReference to the used ReferenceQueue , so if it is GC'ed, Finalizable links {Weak, Soft, Phantom} cannot be live, because they refer to the queue. Therefore, they must be GC'ed before the queue itself can be GC'ed - but still we get the guarantee that these links will be queued in the ReferenceQueue in the order in which they receive the "garbage collection" (as if do they get gc'ed one by one)? The code implies that there is some kind of guarantee, otherwise raw links could theoretically remain in the queue.
thanks
source share