Your mail gives me an idea, though I am not an iota familiar with compiler/garbage collector internals. Can we have some sort of internally maintained priority associated with allocated objects? The garbage collector should look at these objects first when it tries to free anything. The objects which hold other system resources apart from memory, such as file handles, video memory, and so on could be allocated as higher priority objects. Is such a thing possible?<br>
<br><div class="gmail_quote">2008/4/16 Conal Elliott &lt;<a href="mailto:conal@conal.net">conal@conal.net</a>&gt;:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Are Haskell folks satisfied with the practical necessity of imperatively &amp; explicitly reclaiming resources such as file handles, fonts &amp; brushes, video memory chunks, etc?&nbsp; Doesn&#39;t explicit freeing of these resources have the same modularity and correctness problems as explicit freeing of system memory (C/C++ programming)?<br>

<br>I wrote a lovely purely functional graphics library that used video memory to lazily compute and cache infinite-resolution images, and I found that I don&#39;t know how to get my finalizers to run anytime soon after video memory chunks become inaccessible.&nbsp; Explicit freeing isn&#39;t an option, since the interface is functional, not imperative (IO).<br>

<br>I guess I&#39;m wondering a few things:<br><br>* Are Haskell programmers generally content with imperative and bug-friendly interfaces involving explicit freeing/closing of resources?<br>* Do people assume that these resources (or handling them frugally) aren&#39;t useful in purely functional interfaces?<br>

* Are there fundamental reasons why GC algorithms cannot usefully apply to resources like video memory, file descriptors, etc?<br>* Are there resource management techniques that have the flexibility, efficiency, and accuracy of GC that I could be using for these other resources?<br>

<br>Thanks,<br>&nbsp; - Conal<br><br><div class="gmail_quote">2008/4/14 Abhay Parvate &lt;<a href="mailto:abhay.parvate@gmail.com" target="_blank">abhay.parvate@gmail.com</a>&gt;:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

Hello,<br><br>In describing the Handle type, the GHC documentation says (in the System.IO documentation):<br><br><div style="margin-left: 40px;">GHC note: a Handle will be automatically closed when the garbage
 collector detects that it has become unreferenced by the program.
 However, relying on this behaviour is not generally recommended:
 the garbage collector is unpredictable.  If possible, use explicit
 an explicit hClose to close Handles when they are no longer
 required.  GHC does not currently attempt to free up file
 descriptors when they have run out, it is your responsibility to
 ensure that this doesn&#39;t happen.<br></div><br>But one cannot call hClose on Handles on which something like hGetContents has been called; it just terminates the character list at the point till which it has already read. Further the manual says that hGetContents puts the handle in the semi-closed state, and further,<br>


<p>A semi-closed handle becomes closed:
</p><ul><li> if hClose is applied to it;
</li><li> if an I/O error occurs when reading an item from the handle;
</li><li> or once the entire contents of the handle has been read.
</li></ul>So do I safely assume here, according to the third point above, that it&#39;s fine if I do not call hClose explicitly as far as I am consuming all the contents returned by hGetContents?<br><br>Thanks,<br><font color="#888888">Abhay<br>


</font><br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br>