[Mono-devel-list] [Patch] RReader not to rely on bounds checking

Ben Maurer bmaurer at ximian.com
Sun Jan 30 14:43:10 EST 2005


On Sun, 2005-01-30 at 11:29 -0800, Robin Boerdijk wrote:
> >  				StreamReader sr = new StreamReader (filename);
> >  				xml = sr.ReadToEnd ();
> >  				sr.Close ();
> > +				len = xml.Length;
> 
> Isn't there a resource leak here if sr.ReadToEnd() fails? Wouldn't a
> "using" or "try/finally" construct be better here?

There are finalizers, so it will not be leaked. However, it is good
practice to close things like this.

-- Ben




More information about the Mono-devel-list mailing list