<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head><body style="font-family: arial,helvetica,sans-serif; font-size: 13pt"><p><br></p><p>Hi Maurizio<br></p><p><br></p><p>Thank you for your detailed answer. I think that I see what you mean. However, if I keep strong references on the created segments in the factory, I will prevent the garbage collector from doing its job. If I use a weak hash map to store the buffers as keys and records containing arenas and segments as values, maybe it won't work as expected if the segments and/or the arenas strongly refer to the buffers. My main use case works as you describe, the engine creates the direct NIO buffers. How would you design such a factory?<br></p><p><br></p><blockquote type="cite" style="font-family: arial,helvetica,sans-serif; font-size: 13pt;undefined"><p style="font-family: Arial,Helvetica,sans-serif; font-size: 14px;"><strong style="color: #000;">envoyé :</strong> <span style="color: #666;">6 octobre 2023 à 13:33</span><br><strong style="color: #000;">de :</strong> <span style="color: #666;">Maurizio Cimadamore <maurizio.cimadamore@oracle.com></span><br><strong style="color: #000;">à :</strong> <span style="color: #666;">Julien <gouessej@orange.fr>, panama-dev@openjdk.org</span><br><strong style="color: #000;">objet :</strong> <span style="color: #666;">Re: Is it possible to use the FFM API to "free" a direct NIO buffer?</span></p><p><br><br>Hi Julien,<br>we do not have plans to expose arenas in direct buffers.<br><br>The way you get to deterministic deallocation of direct buffers is by <br>creating a segment first, and then exposing a buffer view of the <br>segment. That view will be backed by whatever Arena you used to create <br>the segment, so, if it's a confined arena, you can use it to also free <br>the segment (and hence the buffer view).<br><br>This process is explained in a brand new section of JEP 454:<br><br>https://openjdk.org/jeps/454<br><br>(see "Memory segments and byte buffers").<br><br>If you control the allocation of the direct buffers (which I think you <br>do, otherwise why trying to free them?) this works fine, and doesn't <br>require code to make extensive changes: you only need to create a <br>"factory" for direct buffers which, internally, uses memory segments and <br>arenas.<br><br>Note that your reinterpret call will not work in the way you <br>desire/expect. What you are doing there is constructing a segment out of <br>a byte buffer and then trying to reinterpret the segment to have new <br>temporal bounds. This will NOT cause the buffer to be released when the <br>arena is closed. You have to do it the other way around: first create <br>the segment, then the buffer.<br><br>Maurizio<br><br><br>On 06/10/2023 12:00, Julien wrote:</p></blockquote></body></html>