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:
Ray Greenwell
2009-04-16 22:53:35 +00:00
parent 3300421741
commit dbf20bdc28
@@ -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);
}
}