[gclist] What does a garbage collector do about

David Chase chase@world.std.com
Wed, 31 Jul 2002 22:43:39 -0400


At 11:48 AM 8/1/2002 +1000, Fergus Henderson wrote:
>On 31-Jul-2002, Boehm, Hans <hans_boehm@hp.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.

Mostly to be contrary, I'll disagree.  I spent today farting around
with a newer version of emacs on some version of Linux, copying my
20-year-old keybindings over onto a new machine, and got multiple
annoying messages about a file being "locked for input" when I tried
to write it.  As far as I could tell, it was not locked for input,
but this is the sort of error that I might expect to run into if
GC and finalization were responsible for closing input files (I'm
not saying that this was the cause here, just that today I am sensitive
to the issue).

I think the general rule to follow is that being a good citizen is
desirable and should be attainable, but we should not expect
perfection, and make use of tools (like GC) to smooth over the
problems.

David