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?
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?
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 to null. In fact, all objects that implement IDisposable should be disposed by calling their Dispose method as it the case for GDI objects which require an explicit call to Dispose to free up their resources (see this link for details)
This is being said, if a_label is a WinForms Label then you should do the following to dispose of it:
// REMOVE THE LABEL FROM THE PARENT CONTAINER FIRST
// AND THEN DO THE FOLLOWING
label_array[i].Dispose();
label_array[i] = null;
EDIT
Just to highlight what @Groo mentioned in the comment below, make sure you remove your Label from the parent container before disposing of it, thanks @Groo!
Controls collection.