Anonymous instance implementing IDisposable interface
-
Today I found myself writing / reading binary image files, and I caught myself writing the following on a read:
using(fileReader = new BinaryReader(new FileStream(filePathName, FileMode.Open)))
{
//process the file here
}Before I corrected my self, it got me thinking what exactly happens to anonymous instance members that are implementing the IDisposable interface? Would it be lost after the child instance is the finalized by sitting and waiting to be Garbage Collected? Or in the above example would the FileStream be picked up with the BinaryReader? I do know that if you finalize the parent an instance is based off of, both get finalized... I know not as to what happens above??? :( This might even be a good article, if you could find it among the 1000's of hits on this topics keywords. plz send teh codez? :~
-Spacix All your skynet questions[^] belong to solved
I dislike the black-and-white voting system on questions/answers. X|
-
Today I found myself writing / reading binary image files, and I caught myself writing the following on a read:
using(fileReader = new BinaryReader(new FileStream(filePathName, FileMode.Open)))
{
//process the file here
}Before I corrected my self, it got me thinking what exactly happens to anonymous instance members that are implementing the IDisposable interface? Would it be lost after the child instance is the finalized by sitting and waiting to be Garbage Collected? Or in the above example would the FileStream be picked up with the BinaryReader? I do know that if you finalize the parent an instance is based off of, both get finalized... I know not as to what happens above??? :( This might even be a good article, if you could find it among the 1000's of hits on this topics keywords. plz send teh codez? :~
-Spacix All your skynet questions[^] belong to solved
I dislike the black-and-white voting system on questions/answers. X|
This is interesting. I got the following when I looked
BinaryReader
class through reflectorprotected virtual void Dispose(bool disposing)
{
if (disposing)
{
Stream stream = this.m_stream;
this.m_stream = null;
if (stream != null)
{
stream.Close();
}
}
this.m_stream = null;
this.m_buffer = null;
this.m_decoder = null;
this.m_charBytes = null;
this.m_singleChar = null;
this.m_charBuffer = null;
}Noticed the lines in bold ? it's closing the associated stream but not disposing. Also I noticed
BinaryReader
don't have a destructor. Any thoughts ?All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
This is interesting. I got the following when I looked
BinaryReader
class through reflectorprotected virtual void Dispose(bool disposing)
{
if (disposing)
{
Stream stream = this.m_stream;
this.m_stream = null;
if (stream != null)
{
stream.Close();
}
}
this.m_stream = null;
this.m_buffer = null;
this.m_decoder = null;
this.m_charBytes = null;
this.m_singleChar = null;
this.m_charBuffer = null;
}Noticed the lines in bold ? it's closing the associated stream but not disposing. Also I noticed
BinaryReader
don't have a destructor. Any thoughts ?All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
This is odd, why does did MS even give it an IDisposable interface? Seams that streams don't need finalization and thusly just calling close is all you need.
-Spacix All your skynet questions[^] belong to solved
I dislike the black-and-white voting system on questions/answers. X|