<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">I agree. My use case for this was building a nif for the oracle oci bindings.<div class=""><br class=""></div><div class="">In the happy path users should call the provided db_close function which would flush outstanding transactions and close everything down in the dirty nif.<div class=""><br class=""></div><div class="">The problematic case is where the user's process holding the connection crashes. In that case we need the finaliser as the "secondary" resource reclamation path. If that path cannot safely close the db handle for fear of screwing up the emulator it's a problem.</div><div class=""><br class=""></div><div class="">The solution today is to have an interim process to fault isolate the nif holding process from the user process. Which adds overhead.</div><div class=""><br class=""></div><div class="">Sean<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 25 Nov 2020, at 11:23, Jesper Louis Andersen <<a href="mailto:jesper.louis.andersen@gmail.com" class="">jesper.louis.andersen@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">As a general rule: never use finalizers for the primary resource reclamation path. You don't know when they'll run. You don't know what changes are made to a GC in the future, that alters the rule set slightly. Use them as a safety measure if something goes out of scope. Resources such as DB connections can be very limited in scope (less than 50 for a typical non pg_bouncer postgres setup). So you have to manage them quite explicitly. Memory is far more abundant, and it is also fungible to a large extent, so you just need a block somewhere.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br class=""></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">This is true in *any* GC language I've worked with over the years. There may come something along which completely changes the landscape, but it hasn't happened yet. It's more in the other direction (see e.g., Ephemerons[0]) that things are progressing.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br class=""></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">[0] <a href="https://en.wikipedia.org/wiki/Ephemeron" class="">https://en.wikipedia.org/wiki/Ephemeron</a></div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Nov 25, 2020 at 10:54 AM Sean Hinde <<a href="mailto:sean.hinde@mac.com" class="">sean.hinde@mac.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;" class=""><div class=""><blockquote type="cite" class=""><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none" class=""><br class=""><div class=""><div style="margin:0cm 0cm 0.0001pt 65.2pt;font-size:11pt;font-family:Calibri,sans-serif" class="">This a really nice change. It opens the door to resource destructors being safe for closing external resources like database handles that might take a while.<u class=""></u><u class=""></u></div></div><div class=""><div style="margin:0cm 0cm 0.0001pt 65.2pt;font-size:11pt;font-family:Calibri,sans-serif" class=""><u class=""></u> <u class=""></u></div></div><div class=""><div style="margin:0cm 0cm 0.0001pt 65.2pt;font-size:11pt;font-family:Calibri,sans-serif" class="">Super cool!<u class=""></u><u class=""></u></div></div><div class=""><div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class=""><u class=""></u> <u class=""></u></div><div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class=""><span lang="EN-US" class="">Sorry to disappoint, but no.<u class=""></u><u class=""></u></span></div><div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class=""><span lang="EN-US" class="">By ”scheduled” I just meant “put in run queue to be executed at a later time”. Destructors are still executed by a normal scheduler threads and not dirty schedulers.</span></div></div></div></blockquote><div class=""><br class=""></div><div class="">Ah well! I still think it would be pretty handy. It would make that kind of code much easier to get right, safer, and potentially more efficient.</div><div class=""><br class=""></div><div class="">Sean</div></div><br class=""></div></blockquote></div><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div dir="ltr" class="gmail_signature">J.</div></div>
</div></blockquote></div><br class=""></div></div></body></html>