IDisposable interface
suggest changeRemarks
- It’s up to clients of the class implementing
IDisposableto make sure they call theDisposemethod when they are finished using the object. There is nothing in the CLR that directly searches objects for aDisposemethod to invoke. - It’s not necessary to implement a finalizer if your object only contains managed resources. Be sure to call
Disposeon all of the objects that your class uses when you implement your ownDisposemethod. - 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 boolvariable to your class and setting the value totruewhen theDisposemethod has run.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents