我在想,如果有人能告诉至于内存会发生什么,当出现以下情况:VB6集合/对象引用
Dict = New Dictionary --- Col = New Collection
Dict.Add Key, CustomClassOne
Dict.Add Key2, CustomClassTwo
Dict.Add Key3, CustomClassThree
Dict.Remove Key3
At this point is Key3 removed from memory or would I have to Set Dict.Item(Key3) = Nothing to remove it from memory?
Set Dict = Nothing '// will this remove All the above added custom class objects?
Set Col = Nothing '// Same question as above
唉VB内存管理.... TY您的时间, - 奥斯汀
将设置设置为Nothing并不有用是很简单的,因为在引用变量超出范围之前重新使用引用变量的次数很多。表单级集合可能用于保存数据或对象的列表,这些数据或对象在卸载表单之前会被重新填充并重新处理不同的数据。您也可以在“表单”,“类”等被卸载之前“完成”模块范围字典/集合。在模块实例的生命周期中挂上所有数据并不总是合情合理的。什么时候发布引用没有简单的“不用考虑”规则。 – Bob77 2011-03-25 17:11:00
我明白你的观点,但我认为它很少有一个表单级别的集合,你为了释放内存而设置为无效......当然,你不会有表单级别的集合,而是你可以声明它方法体(因此它会超出范围)。将表单级集合设置为无效可能是一个不值得拥有的集合! – 2011-03-27 01:42:30