As others have correctly noted, the best practice in general is to use using
any time an object implements IDisposable
and you know that the lifetime of the object is going to be short -- that is, not longer than the duration of the current method. Doing so ensures that scarce operating system resources are cleaned up in a timely manner. Even if an object's disposal is "backstopped" by its finalizer, you don't want to be in a situation where, say, you have a lock on a file or database or something that is not going to be released until the finalizer runs several billion nanoseconds from now.
However I would temper that advice by saying that there are a small number of types that implement IDisposable
for reasons other than timely disposal of unmanaged resources. In some very specific cases you can safely skip the using
. However, it is almost never wrong to use using
, even when it is not strictly speaking necessary, so my advice to you is to err on the side of caution and over-use, rather than under-use using
.