RFR 9: 8138696 : java.lang.ref.Cleaner - an easy to use alternative to finalization

Roger Riggs Roger.Riggs at Oracle.com
Tue Oct 20 18:28:24 UTC 2015

Sorry for the silence, JavaOne preparations and the availability of 
folks who wanted
to review have stretched things out.

The Cleaner API was very simple and saw feature creep as the ideas for 
how it might be used
were explored.  There are concerns about committing to supporting 
CleanableReferences in all future JDK versions before there had been a 
chance to
see how if they would be useful and necessary to address the need to 
reduce the
use of finalization within the OpenJDK and beyond.

Recent updates:
  - The Cleaner implementation classes and the CleanableReference 
abstract classes are
    now in the jdk.internal.misc package and are available within the 
java.base module.
  - The Cleanable.clear method has been dropped; there is no current use 
    Since the CleanableReferences extend Reference, clear() is available 
when subclassing.
  - The tests have been extended to cover the exported and internal APIs

The Runnable thunk version is very convenient to code but does 
transparently create
an additional object to hold the bindings.
As the Cleaner is applied to the various uses of finalize we'll see how 
they would be used
and can re-evaluate the exported API needs.

Updated Javadoc:

Updated Webrev:

Thanks, Roger

More information about the core-libs-dev mailing list