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中的键删除值?
答案 0 :(得分:3)
这可能会有所帮助。
var playerControllers:Dictionary = new Dictionary(true);
//弱引用
如果您使用的是Object as key
。在这种情况下我们应该使用weak reference
可能对您有所帮助。
即使你从内存中的stil中删除了playerControllers [id],因为字典类仍然在字典中保存了playerControllers [id]引用。