Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
2.67/5 (3 votes)
See more:
Hi,
I can remove the label of the form so that the address is cleared from memory, but this label was stored in an array. So after deleting a label I want to re-index the array, because there comes a new label. How should I do this?
How do I delete the old array?
Posted
Updated 2-Mar-11 16:12pm
v3
Comments
Sergey Alexandrovich Kryukov 1-Mar-11 22:22pm    
There is no question here.
--SA
Smithers-Jones 1-Mar-11 22:29pm    
I modified the OP's question, hope I understood it the right way.
Toli Cuturicu 4-Mar-11 9:56am    
Non-sense. Ask someone hwo knows a little English to formulate the question for you.

Do you mean resize an array? Well, you cannot.
See here[^] for an alternate solution.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Mar-11 23:17pm    
This is correct, my 5. To avoid confusion, I would add that Array.Resize does not rezise existing array but creates a new one, as explicitly described in help. OP, however, did not mention "resize" (and re-index is not a valid term).
--SA
Abhinav S 1-Mar-11 23:19pm    
Yes good point. Thanks.
Sergey Alexandrovich Kryukov 1-Mar-11 23:29pm    
My answer is ready.
--SA
Few notes here. When you remove a label, you don not clear it from memory. Garbage Collector re-claim memory when all references to an object are lost; it does not happen immediately. So, if you simply remove label and write null in the array where you store it, you really prevent memory leak: if you kept creating and removing labels in cycle without removing it from the container (like your array), you would create a real memory leak.

(There is a misconception that memory leaks are not possible in garbage-collected systems, which is not true, I just explained an essential leak).

Abhinav is of course right about array resize (however, see my comment to his Answer). You should use, for example System.Collection.Generic.List<Label> is you want removable elements.

Finally, I seriously doubt that your UI design with added and removed labels makes sense. You should rather keep you labels but change their properties: Text and, if you want, Location.

—SA
 
Share this answer
 
Comments
Abhinav S 1-Mar-11 23:31pm    
5. :)
Sergey Alexandrovich Kryukov 1-Mar-11 23:33pm    
Thank you.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900