检测对象是否被回收
利用 使用弱引用的Dictionary对象的 key 来存储该对象, gc()后,然后检查 key 是否还存在。
public class ObjectManager
{
private var dic:Dictionary = new Dictionary(true);
/**检测间隔*/
public static var delay:int = 3000;
private static var _ins:ObjectManager;
public function ObjectManager()
{
App.timer.doLoop(delay,check);
}
public static function get ins():ObjectManager{
if (!_ins){
_ins = new ObjectManager;
}
return _ins;
}
private function check():void{
for (var key:* in dic){
trace( dic[key] + "对象还没有被回收");
}
}
/**监测某个对象*/
public function putObject(obj:*,key:String):void{
dic[obj] = key;
}
}
*************************************************