ActionScript3如何使用字典中的键完全删除值

时间:2013-03-04 03:52:29

标签: actionscript-3 dictionary

Dictionary的行为让我困惑: 我有一个Dictionary,像下面那样填充:

var playerControllers:Dictionary = new Dictionary();

playerControllers[id] = new PlayerController();

然后,我正在删除我的一个控制器:

delete playerControllers[id];   //I also tried playerControllers[id] = null;

然后:

for each (var playerController:PlayerController in playerControllers)
{
//"deleted" PlayerController exists! 
}

如何使用Dictionary中的键删除值?

1 个答案:

答案 0 :(得分:3)

这可能会有所帮助。

var playerControllers:Dictionary = new Dictionary(true); //弱引用

如果您使用的是Object as key。在这种情况下我们应该使用weak reference可能对您有所帮助。

即使你从内存中的stil中删除了playerControllers [id],因为字典类仍然在字典中保存了playerControllers [id]引用。

为了更好地理解http://www.adobe.com/devnet/actionscript/learning/as3-fundamentals/associative-arrays.html#articlecontentAdobe_numberedheader_2