本文介绍了Scripting.Dictionary的RemoveAll()方法首先释放所有的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在VB6应用程序中,我有一个字典,其键是 String s,值是自定义的实例类。如果我在字典上调用 RemoveAll(),它会先释放自定义对象吗?或者我自己明确地需要这样做?

  Dim d as Scripting.Dictionary 

d( a)=新的clsCustom
d(b)=新的clsCustom

'这两行是否必要?
设置d(a)=没有
设置d(b)=没有

d.RemoveAll
pre>

解决方案

是的, Dictionary 中的所有对象将在调用 RemoveAll()。从表现(如速度)的观点来看,我会将这些将变量设置为 Nothing 的行是不必要的,因为代码必须首先根据键名查找它们 RemoveAll()将枚举并释放一个循环中的所有内容。


In a VB6 application, I have a Dictionary whose keys are Strings and values are instances of a custom class. If I call RemoveAll() on the Dictionary, 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 to RemoveAll(). From a performance (as in speed) standpoint I would say those lines setting the variables to Nothing are unnecessary, because the code has to first look them up based on the key names whereas RemoveAll() will enumerate and release everything in one loop.

这篇关于Scripting.Dictionary的RemoveAll()方法首先释放所有的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 04:48