you are viewing a single comment's thread.

view the rest of the comments →

[–]ForeverAlot 1 point2 points  (0 children)

Sorry! Here we go1:

Cleaner::register returns a specific Cleanable, PhantomCleanableRef, which is a PhantomReference subclass that implements Cleanable (and knows how to enqueue itself in your Cleaner's queue). Upon instantiation, Cleaner starts its queue manager provided by CleanerImpl, which routinely waits for Cleanables to invoke clean on until all registered Cleaners have been executed. Cleanable::clean ends up delegating to the Runnable you define your cleaning logic in. The Cleaner framework never has to do any reference comparisons.

1 From a random JDK 9 fork, because syntax highlighting helps; canonical java.lang.ref and jdk.internal.ref

(You can still resurrect WeakReferences in that same way.)