Given,
using (var abc = new Abc())
{
// abc is not used here at all.
}
Is it possible the abc is garbage collected before the ending curly brace?
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. internally, there is a reference held to
abcuntil the ending curly brace.The generated IL code looks like this:
When the
usingstatement is turned in to IL code, the compiler actually translates that to a fulltry / finallyblock, and calls the.Dispose()method on your instance ofAbc. So basically it turns it into something like: