WeakReference. Apply directly to the forehead.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5725 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -0,0 +1,36 @@
|
|||||||
|
//
|
||||||
|
// $Id$
|
||||||
|
|
||||||
|
package com.threerings.util {
|
||||||
|
|
||||||
|
import flash.utils.Dictionary;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A weak reference. At some point in the future the referent might not be available
|
||||||
|
* anymore.
|
||||||
|
*/
|
||||||
|
public class WeakReference
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* No, you cannot store undefined here.
|
||||||
|
*/
|
||||||
|
public function WeakReference (referant :Object)
|
||||||
|
{
|
||||||
|
_ref[referant] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the referant, or undefined if it's been collected.
|
||||||
|
*/
|
||||||
|
public function get () :*
|
||||||
|
{
|
||||||
|
for (var k :* in _ref) {
|
||||||
|
return k;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The only way to have a weak reference in actionscript. */
|
||||||
|
protected var _ref :Dictionary = new Dictionary(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user