<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 29/12/2024 10:50, Wojciech Lukowicz
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:CAPeZxVM4QnpFbXw9Ep2O2j3E1y0N_LNoSbXXqPpfUD7bPOgJJA@mail.gmail.com">
      <pre>Turns out AbstractMemorySegmentImpl#reinterpretInternal creates a lambda
wrapper around the cleanup action which captures the original segment
and consequently its scope, doing here what the JavaDoc warns against:
</pre>
    </blockquote>
    <p>This is correct, and subtle. What the code does is this:</p>
    <p>```<br>
      Runnable action = cleanup != null ?<br>
                      () ->
      cleanup.accept(SegmentFactories.makeNativeSegmentUnchecked(address(),
      newSize)) :<br>
                      null;<br>
      ```</p>
    <p>The cleanup action is created against a _fresh_ memory segment
      that points at the same address as the old segment. The fresh
      segment points to the global arena, so it doesn't share anything
      with the old segment. BUT, the use of `address()` inside the
      cleanup action implicitly captures the old segment instance. This
      is a bug.</p>
    <p>Filed:<br>
      <a class="moz-txt-link-freetext" href="https://bugs.openjdk.org/browse/JDK-8347047">https://bugs.openjdk.org/browse/JDK-8347047</a><br>
    </p>
    <p>Thanks<br>
      Maurizio</p>
  </body>
</html>