Stats

318 Contributors: 17
2017-07-22
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook

IDisposable interface

Download c# eBook

Remarks

  • It's up to clients of the class implementing IDisposable to make sure they call the Dispose method when they are finished using the object. There is nothing in the CLR that directly searches objects for a Dispose 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 own Dispose 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 a private bool variable to your class and setting the value to true when the Dispose method has run.

Related Examples