FW: [Mono-list] Buffering for StreamWriter

Marsh, Drew dmarsh@mimeo.com
Thu, 16 May 2002 16:16:28 -0400

Miguel de Icaza [mailto:miguel@ximian.com] wrote:

> My guess is that the file will not be closed when the
> StreamWriter goes out of scope (unless we add ourselves a 
> destructor, but even then, I am not sure if the GC system 
> will guarantee that the destructor will be invoked).

StreamWriter::Close is supposed to call Stream::Close on whatever Stream it
was working with. In the case of a FileStream, calling Close should
obviously close the file. Stream::Close is documented as guarenteeing that
all data written to the Stream *itself* will be Flushed to the underlying
medium. However, if you're layering a StreamWriter over the Stream and have
not closed or flushed the StreamWriter then not all the data will have been
passed off to the Stream. IOW, StreamWriter::Flush does not guarentee a
Stream::Flush. You should always Close at the highest level, in this case is
the StreamWriter, to guarentee that all data is flushed through to whatever
underlying medium is used to store the data.

As far as finalizing/disposing goes, both the finalizer and Close should
simply delegate to the IDisposable::Dispose implementation.