Ad removing finalize eventually (Re: JEP 411 Headaches: Instrumenting private methods in the JDK for authorization checkpoints.

Andrew Haley aph at
Tue Aug 3 09:16:30 UTC 2021

On 8/2/21 7:39 PM, Rony G. Flatscher wrote:

> If the Java ScriptEngine goes out of scope at the Java side its peer
> ooRexx interpreter instance should be terminated, the same is true
> for peer objects for either side (Java peer objects for Rexx
> objects, i.e. Rexx objects being boxed in Java proxy objects, and
> vice versa, ooRexx peer objects for Java objects such that one can
> send messages to an ooRexx peer to the Java side where with
> reflection the appropriate methods get invoked in the corresponding
> Java object).

Sure, but Java doesn't know when a Java ScriptEngine goes out of scope.

Here's the scenario: we're running a generational garbage collector.
Young-generation collections are keeping the heap well within our
limits, so there's no need to do full collections. The ScriptEngine
has been running for a while, so is in the old generation. There's no
reason it will ever be collected. That's why some sort of scoped
access, such as try with resources, is the right way to go if you
really need cleanups to be done.

Andrew Haley  (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <>
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671

More information about the jdk-dev mailing list