Is this working in Dictionary to clean all key reference?
public static function cleanDic(_dic:Dictionary):void
{
for (var eachKey:String in _dic)
{
delete _dic[eachKey];
}
}
I’m worried about, if I delete some key during a for loop will cause not clean all element.
Is this that will happen?
Thanks
I’m not quite sure what you mean by
I’m worried about, if I delete some key during a for loop will cause not clean all element.
but your code sample is correct, that’s how a
Dictionarycan be cleaned. (Assuming that you only useDictionaryobjects withstringkeys, since yourforloop usesstring. See Engineer’s comment below.)Alternatively, you can set your dictionary to a new instance – that achieves the same slightly faster:
The Flash garbage collector should then free all element in the dictionary that’s being thrown away. __