<div dir="ltr">Thanks everyone for the replies, I have a couple of things to try out now.<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Nov 24, 2020 at 7:16 PM Sean Hinde <<a href="mailto:sean.hinde@mac.com">sean.hinde@mac.com</a>> wrote:<br></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;"><br><div><br><blockquote type="cite"><div>On 23 Nov 2020, at 23:16, Sverker Eriksson <<a href="mailto:sverker.eriksson@ericsson.com" target="_blank">sverker.eriksson@ericsson.com</a>> wrote:</div><br><div><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"><div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif"><span lang="EN-US">Prior to OTP 22.0 resource destructors were called directly by the thread that happened to decrease the reference counter down to zero.<u></u><u></u></span></div><div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif"><span lang="EN-US">From OTP 22.0 resource destructors are scheduled. This in order to ensure a stable known execution context for the destructor callback. So it may not have executed when erlang:garbage_collect  returns, but will very soon (unless you have a very overloaded system or a bug preventing ref counter from reaching zero).</span></div><div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif"><span lang="EN-US"><u></u> <u></u></span></div><div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif"><span lang="EN-US">/Sverker, Erlang/OTP<u></u><u></u></span></div><div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif"><span lang="EN-US"><u></u> <u></u></span></div></div></div></blockquote><br></div><div>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.</div><div><br></div><div>Super cool!</div><div><br></div><div>Sean</div><br></div></blockquote></div>