Any known list of IDisposable types?

  • Thread starter Thread starter SlowPoke
  • Start date Start date
S

SlowPoke

The using statement is used with IDisposable objects but is there a known
list of all types which are IDisposable?
 
The using statement is used with IDisposable objects but is there a known
list of all types which are IDisposable?

Hi,

That does not makes sense, in your project you have the one that came
from the framework, the one you declared in your project and those
from any third party libraries you might be using.

why you want to know it?
 
Just attempting to learn to adopt the use of the using statement more
frequently. System.Data and System.IO being two classes which utilize
IDisposable frequently and wondered about other well known circumstances.
 
SlowPoke,

In 20% of the classes IDisposable is implemented simple because formally 20%
of all classes were deriving from Components.

Therefore all those classes get that from component, like 100% of the
classes get the ToString method from Object.

Be aware that if an method is derived does not mean that it is always used
the same. By instance ToString is a typical class that is mostly overridden
used.

Therefore because of the fact that Idisposable is implemented it is not
always needed to use to dispose the unmanaged resources because the
implemented for that is simply done in the base class or in another method
like the close. (Some think that it is needed to dispose an object, but that
is done by the GC)

However, there goes nothing wrong as you invoke the dispose method while it
is does in fact nothing. It cost some time, but that is ignorable. Therefore
this is probably simply implemented in the "using", because checking if it
is needed cost more time.

Cor
 
Cor said:
SlowPoke,

In 20% of the classes IDisposable is implemented simple because
formally 20% of all classes were deriving from Components.

Therefore all those classes get that from component, like 100% of the
classes get the ToString method from Object.

Be aware that if an method is derived does not mean that it is always
used the same. By instance ToString is a typical class that is mostly
overridden used.

Therefore because of the fact that Idisposable is implemented it is
not always needed to use to dispose the unmanaged resources because
the implemented for that is simply done in the base class or in
another method like the close. (Some think that it is needed to
dispose an object, but that is done by the GC)

Then you need to (well, should) implement IDisposable yourself, and call
Dispose on your contained objects from your Dispose. The reasoning you give
results in the rule "never call Dispose from a finalizer".
 
Back
Top