问题描述
EDIT: This question is a duplicate of What is the difference between managed and native resources when disposing? (.NET) and many others. Please answer the others if you have something to add.
According to the Framework Design Guidelines by Krzysztof Cwalina and Brad Abrams, a type that contains instances of disposable types should implement IDisposable.
Is there any other general rule of thumb for when it is best practice to implement IDisposable?
推荐答案
Implement IDisposable when you have a class what wraps an unmanaged resource or when your class has a field that implements IDisposable.
其他推荐答案
When you need to release unmanaged resources, implement IDisposable.
其他推荐答案
From MSDN: http://msdn.microsoft.com/en-us/library/system.idisposable.aspx
Use the Dispose method of this interface to explicitly release unmanaged resources in conjunction with the garbage collector. The consumer of an object can call this method when the object is no longer needed.