package com.exanimo.utils { import flash.utils.Dictionary; /** * * Protects objects from garbage collection. * * @langversion ActionScript 3 * @playerversion Flash 9.0.0 * * @author Matthew Tretter (matthew@exanimo.com) * */ public class GarbageCollectionShield { private var _dict:Dictionary; /** * * Create a new shield. * */ public function GarbageCollectionShield() { this._dict = new Dictionary(); } // // public methods // /** * * Protects an object from garbage collection. * * @param obj * the object to protect * */ public function add(obj:Object):void { this._dict[obj] = true; } /** * * Stops protecting an object from garbage collection. If there are no * references to the object, it will be eligible for collection. * * @param obj * the object to stop protecting * */ public function remove(obj:Object):void { delete this._dict[obj]; } } }