问题描述
在VB6应用程序中,我有一个字典
,其键是 String
s,值是自定义的实例类。如果我在字典
上调用 RemoveAll()
,它会先释放自定义对象吗?或者我自己明确地需要这样做?
Dim d as Scripting.Dictionary
pre>
d( a)=新的clsCustom
d(b)=新的clsCustom
'这两行是否必要?
设置d(a)=没有
设置d(b)=没有
d.RemoveAll
解决方案是的,
Dictionary
中的所有对象将在调用RemoveAll()
。从表现(如速度)的观点来看,我会将这些将变量设置为Nothing
的行是不必要的,因为代码必须首先根据键名查找它们RemoveAll()
将枚举并释放一个循环中的所有内容。In a VB6 application, I have a
Dictionary
whose keys areString
s and values are instances of a custom class. If I callRemoveAll()
on theDictionary
, will it first free the custom objects? Or do I explicitly need to do this myself?Dim d as Scripting.Dictionary d("a") = New clsCustom d("b") = New clsCustom ' Are these two lines necessary? Set d("a") = Nothing Set d("b") = Nothing d.RemoveAll
解决方案Yes, all objects in the
Dictionary
will be released after a call toRemoveAll()
. From a performance (as in speed) standpoint I would say those lines setting the variables toNothing
are unnecessary, because the code has to first look them up based on the key names whereasRemoveAll()
will enumerate and release everything in one loop.这篇关于Scripting.Dictionary的RemoveAll()方法首先释放所有的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!