Creating weak references in Actionscript 3

Posted on 15 August 2007

A 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, there is a way. It's a bit of a hack, and unfortunately uses a full Dictionary object for each weak reference, but it works. The source code is on my public GitHub repository.