Note that there are some explanatory texts on larger screens.

plurals
  1. PODoes GC guarantee that cleared References are enqueued to ReferenceQueue in topological order?
    text
    copied!<p>Say there are two objects, <code>A</code> and <code>B</code>, and there is a pointer <code>A.x --&gt; B</code>, and we create, say, <code>WeakReference</code>s to both <code>A</code> and <code>B</code>, with an associated <code>ReferenceQueue</code>.</p> <p>Assume that both <code>A</code> and <code>B</code> become unreachable. Intuitively <code>B</code> cannot be considered unreachable before <code>A</code> is. In such a case, do we somehow get a guarantee that the respective references will be enqueued in the intuitive (topological when there are no cycles) order in the <code>ReferenceQueue</code>? I.e. ref(A) before ref(B). I don't know - what if the GC marked a bunch of objects as unreachable, and then enqueued them in no particular order? </p> <p>I was reviewing <a href="http://code.google.com/p/guava-libraries/source/browse/trunk/src/com/google/common/base/internal/Finalizer.java" rel="nofollow noreferrer">Finalizer.java</a> of guava, seeing this snippet:</p> <pre><code>private void cleanUp(Reference&lt;?&gt; reference) throws ShutDown { ... if (reference == frqReference) { /* * The client no longer has a reference to the * FinalizableReferenceQueue. We can stop. */ throw new ShutDown(); } </code></pre> <p><code>frqReference</code> is a PhantomReference to the used <code>ReferenceQueue</code>, so if this is GC'ed, no Finalizable{Weak, Soft, Phantom}References can be alive, since they reference the queue. So they have to be GC'ed before the queue itself can be GC'ed - but still, do we get the guarantee that these references will be enqueued to the <code>ReferenceQueue</code> at the order they get "garbage collected" (as if they get GC'ed one by one)? The code implies that there is some kind of guarantee, otherwise unprocessed references could theoretically remain in the queue. </p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload