Objects whose type implements IDisposable should be disposed of by calling Dispose.

If possible, wrap the allocation of the object in a using block to automatically dispose of the object once the using block has completed.

If this is not possible, ensure that Dispose is called on the object. It is usually recommended to call Dispose within a finally block, to ensure that the object is disposed of even if an exception is thrown.

In this example, a FileStream is created, but it is not disposed of.

In the revised example, a using statement is used to ensure that the file stream is properly closed.

  • MSDN: IDisposable Interface.