for example in this code:
void ButtonCreator()
{
Button elboton = new Button();
}
what happens with elboton after I call this method?
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.
If they’re not referenced by some other object (e.g. a container), then they become unreachable and are eligible for collection by the garbage collector. This is the same as creating any other object.
Note that the
System.Windows.Forms.Controlclass (and its subclasses likeButton) all implement theIDisposableinterface, so the easiest way to make sure any unmanaged resources associated with theButtonare released is to use ausingblock, like so:However, any managed resources associated with the object won’t be reclaimed until the GC runs, regardless of whether or not you use a
usingblock.