[gclist] What does a garbage collector do about
Thu, 1 Aug 2002 11:48:13 +1000
On 31-Jul-2002, Boehm, Hans <email@example.com> wrote:
> We all agree that file descriptors should be explicitly closed (or
> closed by a C++-style destructor for an object with a known lifetime)
> whenever possible.
I don't agree with that.
There's a fundamental difference here between file descriptors opened in
input mode, and file descriptors opened in output mode.
For file descriptors opened in input mode, if the GC and file open routine
do a good enough job of reclaiming unreachable file descriptors so that
you won't run out of file descriptors, there's no need to explicitly
close them. In general I wouldn't expect errors to occur when closing
files opened in input mode, and I think it should be fairly safe to
ignore such errors if they do occur.
For file descriptors opened in output mode, the close operation normally
flushes any pending buffered output operations to the OS. It is very
important for programs to properly report errors from such operations.
Hence they should be explicitly closed (or equivalent).
Fergus Henderson <firstname.lastname@example.org> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.