Ad removing finalize eventually (Re: JEP 411 Headaches: Instrumenting private methods in the JDK for authorization checkpoints.
aph at redhat.com
Mon Aug 2 15:27:54 UTC 2021
On 7/27/21 11:01 AM, Rony G. Flatscher wrote:
> Background of the question: in an ooRexx-Java bridge for each Java object an ooRexx peer object gets
> created and needs to exist as long as the Java object exists. Once the Java object gets garbage
> collected the ooRexx peer object needs to be freed as well. The bridge between ooRexx (an
> interpreted, message based, dynamically typed language) and Java is realized via JNI. Currently
> (actually since 20 years) on the Java side the finalize method gets employed to signal to ooRexx
> that its ooRexx peer object needs to be removed.
One problem is that there's no guarantee that peers ever get removed until
a Java program ends, and maybe not even then, so if you actually need that
to happen finalizers are not what you need. And if you don't need cleanups
to happen, you won't be affected.
The "more flexible and efficient" ways to do it are ReferenceQueues, but
they'll still suffer from the same problem.
Andrew Haley (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671
More information about the jdk-dev