我可以删除表格的标签 [英] I can remove the label of the form
本文介绍了我可以删除表格的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以删除表格的标签,以便从内存中清除地址,但是此标签存储在数组中.因此,删除标签后,我想重新索引数组,因为有一个新标签.我该怎么办?
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?
推荐答案
您是说要调整数组大小?好吧,你不能.
请参见此处 [
Do you mean resize an array? Well, you cannot.
See here[^] for an alternate solution.
此处很少注意.删除标签时,不会从内存中清除它.当丢失对对象的所有引用时,垃圾收集器将回收内存;它不会立即发生.因此,如果仅删除标签并在存储它的数组中写入null
,就可以真正防止内存泄漏:如果您不断循环创建和删除标签而不将其从容器中删除(例如您的数组),则可以创建真正的内存泄漏.
(有一个误解,认为在垃圾收集系统中不可能发生内存泄漏,这是不正确的,我只是解释了一个重要的泄漏).
Abhinav当然对数组调整大小是正确的(但是,请参阅我对他的答案的评论).您应该使用,例如System.Collection.Generic.List<Label>
是您想要可移动的元素.
最后,我严重怀疑带有添加和删除标签的UI设计是否有意义.您应该保留标签,但要更改其属性:Text
,如果需要,还可以更改Location
.
—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 writenull
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 exampleSystem.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
这篇关于我可以删除表格的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文