Is it reasonable to make a rule against explicitly calling Dispose() on an IDisposable object?
Are there any cases where a using statement cannot properly ensure an IDisposable object is cleaned up?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No.
There are certainly cases where it makes no sense to use
usingto dispose an object for you. For example, all cases where the desired lifetime of the object is not bound by a particular activation of a method containing ausingstatement.Consider for example a disposable object which “takes over management” of another disposable object. The “outer” object may well be disposed by a
usingblock, but how is the “inner” object, likely stored in a private field of the outer object, to be disposed without an explicit call toDispose()?