I have a label array pointing to a label such as,
label_array[i] = a_label;
The array has global while label has function scope. Is it possible to delete label via array?
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.
Usually, you can dispose of your objects just by setting their references to
null, the garbage collector will take care of disposing of those objects for you. However, not all objects can be disposed just by setting their reference tonull. In fact, all objects that implementIDisposableshould be disposed by calling theirDisposemethod as it the case for GDI objects which require an explicit call toDisposeto free up their resources (see this link for details)This is being said, if
a_labelis a WinFormsLabelthen you should do the following to dispose of it:EDIT
Just to highlight what @Groo mentioned in the comment below, make sure you remove your
Labelfrom the parent container before disposing of it, thanks @Groo!