When to implement IDisposable

  • Thread starter Thread starter Miguel
  • Start date Start date
M

Miguel

Could someone explain to me when a self-written class should implement
the IDisposable interface?
I'm wondering this because I use quite a lot of P/Invokes in my
application (I'm not using the LocalAlloc Invoke of which I could cause
a leak)

Kind regards

Miguel
 
If your "self-written" class holds unmanaged resources (or holds objects
that themselves hold unmanaged resources i.e. they implement IDisposable),
then you should implement IDisposable.

Unmanaged resources are typically handles (that if not closed cause problem
to the system).

Any reference on Dispose on the web would have given you the above so if you
have a specific example in mind feel free to share.

Cheers
Daniel
 
Back
Top