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

Roman Kennke rkennke at redhat.com
Wed Aug 4 19:13:19 UTC 2021


> O.K. now having implemented PhantomReferences to replace the usage of finalize() in the bridge it
> turns out that finalize() gets invoked "magnitudes" of times (100 and more finazable objects in
> different gc runs within a total run of five seconds) more often than their PhantomReferences are
> being put on the reference queue (not a single one!) to allow to carry out the necessary finalizations!

I'd suggest that you verify if you've done it correctly. 
PhantomReferences and Finalizers are handled during the same pass during 
GC. If no PhantomRefs show up, then it's probably still reachable? A 
twist may be when the referent has a finalize() method, then it will not 
get enqueued until finalize() has been called (and object remains 
unreachable).

finalize() is *not* much better than PhantomReference.

Roman



More information about the jdk-dev mailing list