IDisposable interface
suggest changeRemarks
- It’s up to clients of the class implementing
IDisposable
to make sure they call theDispose
method when they are finished using the object. There is nothing in the CLR that directly searches objects for aDispose
method to invoke. - It’s not necessary to implement a finalizer if your object only contains managed resources. Be sure to call
Dispose
on all of the objects that your class uses when you implement your ownDispose
method. - It’s recommended to make the class safe against multiple calls to
Dispose
, although it should ideally be called only once. This can be achieved by adding aprivate bool
variable to your class and setting the value totrue
when theDispose
method has run.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents