RFR: 8347047: Cleanup action passed to MemorySegment::reinterpret keeps old segment alive
Brent Christian
bchristi at openjdk.org
Tue Jan 7 19:40:47 UTC 2025
On Tue, 7 Jan 2025 10:44:22 GMT, Per Minborg <pminborg at openjdk.org> wrote:
> This PR proposes to eliminate the capturing of `this` in the cleanup action of `AbstractMemorySegment::reinterpretInternal`.
As a matter of style, I believe there is something to be said for writing out cleaning actions as static nested classes, as one can/must include explicit fields for all object and values that the `Runnable` object must reference. But it's more verbose, of course.
Also, some conversions of finalizer to Cleaner have included tests to ensure that objects become unreachable as expected. (A relatively simple technique is to add the objects in question into a WeakHashMap, and ensure they are removed as expected.) [GssContextCleanup.java](https://github.com/openjdk/jdk/blob/master/test/jdk/sun/security/jgss/GssContextCleanup.java) and [GssNameCleanup.java](https://github.com/openjdk/jdk/blob/master/test/jdk/sun/security/jgss/GssNameCleanup.java) from [JDK-8284490](https://bugs.openjdk.org/browse/JDK-8284490) are examples. I don't know if it's practical to construct such a test in this case.
Anyway, just a couple things to think about.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/22943#issuecomment-2576085140
More information about the core-libs-dev
mailing list