On Dec 8, 2015, at 2:26 PM, Peter Levart <peter.lev...@gmail.com> wrote: > > On 12/08/2015 07:25 PM, Kim Barrett wrote: >> On Dec 8, 2015, at 3:09 AM, David Holmes <david.hol...@oracle.com> >> wrote: >> >>> Question: what happens if an object is registered simultaneously with >>> multiple Cleaners? Do we need to warn the user against that? >>> >> Aside: I like David's suggested "action" terminology. >> >> >>> Question: what happens if an object is registered simultaneously with >>> multiple Cleaners? Do we need to warn the user against that? >>> >> Registering an object with multiple Cleaners, or even the same Cleaner >> multiple times, is not a problem, so long as the various cleanup >> actions can cope with that. This is even expected to occur in >> practice. Consider the conversion of a class hierarchy away from >> using finalize() to instead using Cleaners. A base class may register >> a cleanup action for the state associated with that (base) class. A >> derived class may independently register a cleanup action for the >> additional state associated with that derived class. The derived >> class's cleanup action might be registered with the same or a >> different Cleaner than that used by the base class. >> >> > > One thing to note is that independent actions registered on the same referent > may execute in arbitrary order (each registration is a separate > PhantomReference). If order is important then something like the following > will be required:
Yes, although I think such interactions will turn out to be quite rare in practice, once the different cleanups no longer need to take into consideration the registered object.