If the class has an instance field that implements IDisposable, then the containing class implements IDisposable and the class that processes the Dispose method from its Dispose method.
public class A : IDisposable { public System.Drawing.Font font = new Font("Arial", 10.0f); public void Dispose() { font.Dispose() } }
(I know that I did not install the template correctly, but for the sample code should be enough)
If the field is a static field, then where should the call in the Dispose field be?
public class B { public static System.Drawing.Font font = new Font("Arial", 10.0f); }
I could make class B an IDisposable implementation and have this call to font.Dispose , but if later, B.font will be used later, it will cause problems. In addition, you will need to remember that when accessing the static method, you need to create an instance to call Dispose.
I could also create a static Dispose method, but then users must remember that you are calling Dispose and must make sure that they are the last user of this in the program.
source share