Thanks! I was worried about how/where would I place hClose!<br><br><div class="gmail_quote">On Mon, Apr 14, 2008 at 10:58 PM, Brent Yorgey <<a href="mailto:email@example.com">firstname.lastname@example.org</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br><div class="gmail_quote">2008/4/14 Abhay Parvate <<a href="mailto:email@example.com" target="_blank">firstname.lastname@example.org</a>>:<div><div></div><div class="Wj3C7c"><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'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's fine if I do not call hClose explicitly as far as I am consuming all the contents returned by hGetContents?<br></blockquote></div></div>
Yes, not only is it fine, it's recommended! Calling hClose explicitly on a handle after calling hGetContents is a sure way to introduce bugs.<br><br>-Brent<br></div></div><br>