9
One thing that none of the answers so far have mentioned is that you should dispose the object if Gimme() throws an exception. For example:
MyDisposableObject Gimme()
{
MyDisposableObject disposableResult = null;
try
{
disposableResult = ...
// ... Code to prepare disposableResult
return disposableResult;
}
catch(Exception)
{
if (disposableResult != null) disposableResult.Dispose();
throw;
}
}