On Fri, 13 Jan 2023 07:45:59 GMT, Daniel Jeliński <[email protected]> wrote:
> As far as I could tell, the cleaners you pointed out use local variables
> only. As long as the lambda does not reference any object fields or instance
> methods, `this` is not captured.
Ok. So the lambda needs to reference a field of the `this` in order to capture
`this`. I guess that's why you see hacks like this:
// Register a cleaning function to close the handle
final long local_handle = handle; // local to prevent capture of this
CleanerFactory.cleaner().register(this, () ->
closeHandle(local_handle));
-------------
PR: https://git.openjdk.org/jdk/pull/11965