finalize() *much* better than PhantomReferences (Re: Ad removing finalize eventually (Re: JEP 411 Headaches: Instrumenting private methods in the JDK for authorization checkpoints.

Kim Barrett kim.barrett at
Thu Aug 5 01:21:37 UTC 2021

> On Aug 4, 2021, at 9:11 PM, Hans Boehm <hboehm at> wrote:
> One complication with bare PhantomReferences (as opposed to e.g. Cleaners) is that you need to make sure that the Reference itself is kept reachable, by putting it in some reachable data structure. As the spec says: "If a registered reference becomes unreachable itself, then it will never be enqueued." Normally the ReferenceQueue processing code will need to remove it from that data structure. There's typically a fair amount of boilerplate involved in correct use.
> I think this can be unexpected for users. Could that be causing the problem here?

That sounds like a good guess.

More information about the jdk-dev mailing list