In addition to the links Herfried provided I'd like to point out some
of the rules I use when deciding to implement IDisposable and
overridding Finalize. It's not clearly indicated in the MSDN articles.
* DO implement IDisposable if your class directly uses unmanaged
resources.
* DO implement IDisposable if your class indirectly uses unmanaged
resources. For example, if your class has a reference to another
object that implements IDisposable.
* DO override the Finalize method if your class directly uses unmanaged
resources.
* DON'T override the Finalize method if your class does not directly
use managed resource. In other words, don't override Finalize just
because your class has a reference to another class that implements
IDisposable.
* DON'T override the Finalize method in a class who's base class
already overrides Finalize. In other words, if the base class provides
the protected Dispose(disposing as Boolean) method then you don't need
to override Finalize.
* DON'T implement IDisposable if your class does not retain unmanaged
resources either directly or indirectly. In other words, don't
implement IDisposable just because a method on your class has a local
reference to a class that implements IDisposable or because that method
uses unmanaged resources locally. Just make sure that the method calls
Dispose on all local objects that implement IDisposable and releases
all unmanaged resources that are local to the method.
Brian
Siv wrote:
Hi,
I have a class module that I have created and I have looked at the various
descriptions of how you should implement a dispose method in your own class
and I am finding it mighty confusing. Does anyone have an example of the
correct way to implement a dispose method or a link to an understandable
site that has this information.
Thanks for your help.
--
Siv
Martley, Near Worcester, UK.