From: rodrigo vanegas
Subject: garbage collecting streams
Date: 
Message-ID: <RV.93Jul18155420@fiji.cs.brown.edu>
Are streams automatically closed when they are garbage collected?  In
other words,

  (let (s)
    (open "s")
    (format s "Hello, World!"))

is this equivalent to a with-open-file?


rodrigo vanegas
··@cs.brown.edu

From: rodrigo vanegas
Subject: Re: garbage collecting streams
Date: 
Message-ID: <RV.93Jul18201350@fiji.cs.brown.edu>
In article <················@fiji.cs.brown.edu>, ··@cs.brown.edu (rodrigo vanegas) writes:

>   (let (s)
>     (open "s")
>     (format s "Hello, World!"))

I mean

  (let (s)
    (setf s (open "s"))
    (format s "Hello, World!"))


rodrigo vanegas
··@cs.brown.edu
From: Barry Margolin
Subject: Re: garbage collecting streams
Date: 
Message-ID: <22d57uINNoi5@early-bird.think.com>
In article <················@fiji.cs.brown.edu> ··@cs.brown.edu (rodrigo vanegas) writes:
>Are streams automatically closed when they are garbage collected?  In
>other words,
>
>  (let (s)
>    (setq s (open "s"))
>    (format s "Hello, World!"))
>
>is this equivalent to a with-open-file?

No.

The Common Lisp specification prescribes nothing about garbage collection
(it only mentions in passing that GC is assumed to occur), so
implementations certainly aren't required to close streams when they GC
them.  Also, WITH-OPEN-FILE is required to close the file as soon as you
exit the form, but garbage collection can occur arbitrarily long after
exiting the above, so even in a system that did close streams when they GC
them the two versions wouldn't be equivalent.  It's also possible that such
an implementation would close the stream in abort mode, so some or all of
the output could be discarded.

I don't know of any implementations that close streams automatically when
they GC them.  Some implementations provide "finalizations", which allow
you to specify a function that should be run before particular objects are
GCed, so this would allow you to implement this feature yourself.


-- 
Barry Margolin
System Manager, Thinking Machines Corp.

······@think.com          {uunet,harvard}!think!barmar
From: Christopher Hoover
Subject: Re: garbage collecting streams
Date: 
Message-ID: <CAEDvJ.65L.1@cs.cmu.edu>
In article <············@early-bird.think.com> ······@think.com (Barry Margolin) writes:

>I don't know of any implementations that close streams automatically when
>they GC them.  Some implementations provide "finalizations", which allow
>you to specify a function that should be run before particular objects are
>GCed, so this would allow you to implement this feature yourself.

CMU Common Lisp will automatically close garbage streams created by
OPEN.  This is done via a simple finalization mechanism (written by
William Lott) that is based on the weak pointer support that I hacked
into the garbage collector.

-- Chris.
(··@lks.csi.com)
From: Timo Gerbes - DA Thomas
Subject: Re: garbage collecting streams
Date: 
Message-ID: <1993Jul19.120226@informatik.uni-kl.de>
in cltl1 on page 423:

=================================================================================
implementation note: while with-open-file tries to automayically close the stream
on exit from the construct, for robustness it is helpful if the garbage collector
can detect discarded streams and automatically close them.
=================================================================================

it is up to the implementation, but i believe most of the GC will detect
discarded streams.

	timo 
From: Martin Cracauer
Subject: Re: garbage collecting streams
Date: 
Message-ID: <1993Jul19.200741.2149@wavehh.hanse.de>
··@cs.brown.edu (rodrigo vanegas) writes:

>Are streams automatically closed when they are garbage collected?  In
>other words,

The real question is: Can one attach a destructor with an object that
is called when the objects is destroyed by a garbage collector? Would
be very useful at least for every object that creates data structures
in the underlying operating system.




-- 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Martin Cracauer <········@wavehh.hanse.de>,Voice+4940-5221829,Fax.-5228536
------ C is a good language - for implementing programming systems -------