|
WeakRef
To create weak references to an object.
WeakRef classA weak reference is a reference that does not prevent the object from being garbage collected. It's great that Actionscript 3 has weak references in the EventDispatcher and Dictionary classes. But sometimes you want to create your own weak references. Something along the lines of var weak:WeakRef = new WeakRef( someObject ); Well, this class lets you do that. To use the class // Create a weak reference
var weak:Weakref = new WeakRef( obj );
// Later, use the referenced object
var strong = weak.get();
if( strong != null )
{
// use strong here
}
else
{
// garbage collector has already disposed of the object
}If the get method returns null then the object has been garbage collected. |
Sign in to add a comment