[Haskell-cafe] Re: Are handles garbage-collected?

Stefan Monnier monnier at iro.umontreal.ca
Sun Oct 24 19:34:04 EDT 2004

> File descriptors aren't simply a "resource" in the sense that memory
> is. Closing a descriptor may have significance beyond the process
> which closes it. If it refers to the write end of a pipe or socket,
> closing it may cause the reader to receive EOF; if it refers to a
> file, any locks will be released; and so on.

Yes, I think this is the crux of the matter: closing a file-descriptor is
not just a question of releasing resources, but it has actual side-effects
visible by the outside world (e.g. closing a pipe, or actual write-back if
the file is on NFS, ...) so it is important for programs to close FDs
explicitly when it needs to happen, rather than leave it to the GC to do it
whenever it feels like (which can be much much later if you get unlucky with
your generations).


More information about the Haskell-Cafe mailing list