<HTML><BODY>Then how?<br><br>Suppose I have<br>(struct obj (file))<br>(define my-obj (obj (open-output-file "out.dat")))<br><br>What I have to write to close the file, when my-obj will be GC'ed?<br><br>I can write<br>(define will (make-will-executor))<br>(will-register will my-obj (lambda (x) (close-output-port (obj-file x))))<br><br>But as far as I understand, it will not be called until `will-execute' or `will-try-execute' will be manually called?<br><br>Then how to call will-try-execute when GC is collecting my-obj?<br><br><br>Sat, 2 Aug 2014 11:57:32 +0100 от Matthew Flatt <mflatt@cs.utah.edu>:<br>
<blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;">
<div id="">
<div class="js-helper js-readmsg-msg">
<style type="text/css"></style>
<div>
<base target="_self" href="https://e.mail.ru/">
<div id="style_14069770660000000607_BODY">No, use the safe "will executors" API, instead.<br>
<br>
The unsafe finalizer API is for low-level, atomic finalization. Closing a port can flush buffers and more, and it's not a good idea to do that in an unsafe atomic context.<br>
<br>
> On Aug 2, 2014, at 11:12 AM, Roman Klochkov <<a href="/compose?To=kalimehtar@mail.ru">kalimehtar@mail.ru</a>> wrote:<br>
> <br>
> I have a structure, that has a filestream inside it. File have to be cosed, when the structure is not used anymore (so gargbage collected).<br>
> <br>
> Is the best way to do<br>
> (require ffi/unsafe)<br>
> (register-finalizer my-obj<br>
> (lambda (x) (close-output-port (obj-file x))))<br>
> <br>
> ?<br>
> <br>
> It seems doing right thing, but why `ffi/unsafe'? Is it OK, when my program actually doesn't use FFI?<br>
> <br>
> <br>
> -- <br>
> Roman Klochkov<br>
> ____________________<br>
> Racket Users list:<br>
> <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</div>
<base target="_self" href="https://e.mail.ru/">
</div>
</div>
</div>
</blockquote>
<br>
<br>-- <br>Roman Klochkov<br></BODY></HTML>