Question on implementing IDisposable
- From: "phl" <killkennyhouse@xxxxxxxxxxx>
- Date: 29 May 2006 02:30:45 -0700
hi,
My question is:
1. To avoid possible memory leaks, when you use this pattern, after you
have dealth with the unmanaged resources and before you take your
object off the finalize queue, how are you sure that your managed
object resources are completely freed up of resources it's might be
using? In my case below I have a private bool variable. Are there any
other managed resource that you might need to explicitly free up in
Dispose?
2. I have the example in msdn that instanciates a Component object but
doesn't actually do anything with it, what is this class for?
Thanks
-phl
Here's some pseudo code:
public classA : IDisposable
{
private Component component = new Component(); //WHAT IS THIS
FOR????
private XmlTextReader reader;
private bool disposed = false;
public LoadFile(string FilePath)
{
reader = new XmlTextReader(FilePath);
}
public void CloseFile()
{
reader.Close();
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
public void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
CloseFile();
//are there anything else you need to free up
here?????
}
}
this.disposed = true;
}
ClassA()
{
Dispose(false);
}
}
.
- Follow-Ups:
- Re: Question on implementing IDisposable
- From: Barry Kelly
- Re: Question on implementing IDisposable
- Prev by Date: ASP.NET Generic template (2)
- Next by Date: How to...
- Previous by thread: ASP.NET Generic template (2)
- Next by thread: Re: Question on implementing IDisposable
- Index(es):
Relevant Pages
|