<html><head></head><body bgcolor="#FFFFFF"><div>Just to clarify, this guarantee possibly could be made, ghc just doesn&#39;t do it now. In the past ghc never guaranteed a finalizer would ever be run.<br><br>Regardless I would be wary of trusting finalizers to clean up very scarce resources. A malloc&#39;d buffer is probably fine to have a finalizer for, texture objects or file descriptors are a different matter. Predictability matters in those cases.<br>
<br>Sent from my iPhone^H^H^H^H^HPortable Turing machine</div><div><br>On Feb 6, 2012, at 10:16 PM, Austin Seipp &lt;<a href="mailto:mad.one@gmail.com">mad.one@gmail.com</a>&gt; wrote:<br><br></div><div></div><blockquote type="cite">
<div><div>It&#39;s a precise GC of course (conservative collection would be madness considering how much memory Haskell programs chew through.) <span class="Apple-style-span" style>That still doesn&#39;t ensure your finalizer will run during the next GC even if all the references are gone by then.</span></div>

<div><br>Sent from my iPhone^H^H^H^H^HPortable Turing machine</div><div><br>On Feb 6, 2012, at 10:09 PM, Clark Gaebel &lt;<a href="mailto:cgaebel@csclub.uwaterloo.ca">cgaebel@csclub.uwaterloo.ca</a>&gt; wrote:<br><br></div>

<div></div><blockquote type="cite"><div><font face="verdana,sans-serif">Is the Haskell garbage collector conservative, or precise?<br><br>If it&#39;s conservative, then this will only usually work. If it&#39;s precise, it should always work.<br>

</font><br><div class="gmail_quote">

On Mon, Feb 6, 2012 at 10:56 PM, Ben Lippmeier <span dir="ltr">&lt;<a href="mailto:benl@ouroborus.net">benl@ouroborus.net</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



<div class="im"><br>
On 07/02/2012, at 2:50 PM, Clark Gaebel wrote:<br>
<br>
&gt; I would be running the GC manually at key points to make sure it gets cleaned up. Mainly, before any scene changes when basically everything gets thrown out anyways.<br>
<br>
<br>
</div>From the docs:<br>
<br>
newForeignPtr :: FinalizerPtr a -&gt; Ptr a -&gt; IO (ForeignPtr a)Source<br>
Turns a plain memory reference into a foreign pointer, and associates a finalizer with the reference. The finalizer will be executed after the last reference to the foreign object is dropped. There is no guarantee of promptness, however the finalizer will be executed before the program exits.<br>




<br>
<br>
&quot;No guarantee of promptness&quot;. Even if the GC knows your pointer is unreachable, it might choose not to call the finaliser. I think people have been bitten by this before.<br>
<span class="HOEnZb"><font color="#888888"><br>
Ben.<br>
<br>
<br>
</font></span></blockquote></div><br>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>Haskell-Cafe mailing list</span><br><span><a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a></span><br>

<span><a href="http://www.haskell.org/mailman/listinfo/haskell-cafe">http://www.haskell.org/mailman/listinfo/haskell-cafe</a></span><br></div></blockquote>
</div></blockquote></body></html>