I have spent a lot of time researching the disposing of objects, the disposable interface and finalizers. I have mostly understood how it works, but I was not able to find a clear stance on what to do with some types of fields once an object has been disposed.
To illustrate, I have a class that stores some object references in fields:
public class ImageCropper : IDisposable
{
private Image workImage;
private Point cropOrigin;
private List<MoveIncrement> moveAmounts;
private Movie movie;
}
My Dispose
method then does the following (omitting the handling of the disposed state here in the example):
protected virtual void Dispose(bool disposing)
{
workImage.Dispose(); // Is disposable, so as a general rule, dispose of it
// cropOrigin is not disposable, ignore it
// moveAmounts is not disposable, ignore it
movie = null; // Not disposable, but remove the reference to help the garbage collector
}
Is this the right way to do it?