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

Alan Bateman Alan.Bateman at oracle.com
Wed Oct 14 14:01:20 UTC 2015


On 14/10/2015 14:54, Roger Riggs wrote:
> Being able to subclass the XXXCleanable classes allows more efficient 
> implementation of the cleaners
> in both size and performance.  The subclass adds the necessary state 
> for the cleanup and implements
> the performCleanup method.  Only a single object is created (and 
> gc'd), reducing the size of headers
> and cross references between separate objects.  Only the 
> performCleanup method is overridable to
> maintain the robustness of the Cleaner implementation.
>
> If the XXXCleaner classes are not subclassed, a separate object is 
> needed for the state and behavior.
> Either that extra object is created by the binding if lambda is used, 
> or by the class needing the cleanup.
> It is not a big cost but is proposed to optimize the design and 
> implementation.
>
> Peter's email [1] provided another description of the use case for 
> subclassing.
>
> I'm working on a webrev to show how the Cleaner would be used instead 
> of finalizers
> and it will show use use of both lambdas and explicit cleanup classes.
No issue with sub-classing for the implementation, it's just not clear 
why they need to be in the public API.

-Alan



More information about the core-libs-dev mailing list