|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
XmlTextReader disposal patternI am amazed that XmlTextReader does not implement IDispoable. Is there any reason? In the case of XmlTextReader( Stream ) construction, if I wrap the Stream with a C# using statement like this: using( StringStream ss = new StringStream.... ) { XmlTextReader xr = new XmlTextReader( ss ); // ... use xr } Will this upset the XmlTextReader's finalizer because that would be executed non-deterministically long after ss has been disposed? If inside the using() loop, I called XmlTextReader.Close(), will this upset the ss.Dispose() call? Thanks. Leon Leon wrote:
> Hi, XmlTextReader does implement IDisposable (inherited from XmlReader) in .NET > > I am amazed that XmlTextReader does not implement IDispoable. Is > there any reason? 2.0. Apparently this was overlooked in 1.x. > In the case of XmlTextReader( Stream ) construction, if I wrap the No. XmlTextReader in 1.0 doesn't have a finalizer (although the VS2003 docs > Stream with a C# using statement like this: > using( StringStream ss = new StringStream.... ) > { > XmlTextReader xr = new XmlTextReader( ss ); > // ... use xr > } > > Will this upset the XmlTextReader's finalizer because that would be > executed non-deterministically long after ss has been disposed? incorrectly state that it does). In 2.0, the finalizer won't touch the wrapped stream - it's too late at that point. > If inside the using() loop, I called XmlTextReader.Close(), will this No, the stream will know that it's closed and won't do anything in Dispose.> upset the ss.Dispose() call? -cd Thanks.
Another good reason to use .Net 2 ;-) Leon Show quote "Carl Daniel [VC++ MVP]" wrote: > Leon wrote: > > Hi, > > > > I am amazed that XmlTextReader does not implement IDispoable. Is > > there any reason? > > XmlTextReader does implement IDisposable (inherited from XmlReader) in .NET > 2.0. Apparently this was overlooked in 1.x. > > > In the case of XmlTextReader( Stream ) construction, if I wrap the > > Stream with a C# using statement like this: > > using( StringStream ss = new StringStream.... ) > > { > > XmlTextReader xr = new XmlTextReader( ss ); > > // ... use xr > > } > > > > Will this upset the XmlTextReader's finalizer because that would be > > executed non-deterministically long after ss has been disposed? > > No. XmlTextReader in 1.0 doesn't have a finalizer (although the VS2003 docs > incorrectly state that it does). In 2.0, the finalizer won't touch the > wrapped stream - it's too late at that point. > > > If inside the using() loop, I called XmlTextReader.Close(), will this > > upset the ss.Dispose() call? > > No, the stream will know that it's closed and won't do anything in Dispose. > > -cd > > > |
|||||||||||||||||||||||