<!DOCTYPE html>
<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hello,</p>
    <p>currently you have to choose between these Arena types:<br>
    </p>
    <ul>
      <li>`ofAuto`: Garbage collected, manual cleaning not possible<br>
      </li>
      <li>`ofConfined`, `ofShared`: Not garbage collected, manual
        cleaning</li>
      <li>(`global`)<br>
      </li>
    </ul>
    <p>This is a bit inconvenient for an application which wants to free
      memory as soon as possible (`ofConfined` / `ofShared`). Because if
      it forgets to close the Arena in some call paths, it causes a
      memory leak. Ideally you would always use try-with-resources, but
      that is not possible in all situations. So a combination of both
      manual closing and GC tracking would be useful in some situations.<br>
    </p>
    <p>Maybe you can work around this by creating a custom Arena for
      which:</p>
    <ul>
      <li>a delegate 'confined' or 'shared' Arena exists</li>
      <li>a `java.lang.ref.Cleaner` is used which closes the delegate
        Arena</li>
      <li>the `allocate` method obtains a segment from the delegate, but
        then uses `reinterpret` to attach it to the wrapping custom
        Arena</li>
      <li>the `close` method calls `cleanable.clean()` (and to satisfy
        throwing IllegalStateException on double close maybe an
        AtomicBoolean tracking the state; cannot directly call `close`
        on delegate because during GC Cleaner might then encounter an
        IllegalStateException when it calls `close` as well)</li>
      <li>the `scope` method returns the scope of the delegate Arena<br>
      </li>
    </ul>
    <p>Is that the suggested solution here?</p>
    <p><br>
    </p>
    <p>Or would it make sense if the JDK provided such Arena variants,
      respectively added a method for marking a 'confined' or 'shared'
      Arena to be managed by garbage collection?</p>
    <p><br>
    </p>
    <p>Kind regards<br>
    </p>
  </body>
</html>