Weak reference and Strong reference

Posted by theband on Stack Overflow See other posts from Stack Overflow or by theband
Published on 2010-05-06T12:16:18Z Indexed on 2010/05/06 12:28 UTC
Read the original article Hit count: 262

Filed under:
|
package uk.co.bigroom.utils 
{
    import flash.utils.Dictionary;
    /**
     * Class to create a weak reference to an object. A weak reference
     * is a reference that does not prevent the object from being
     * garbage collected. If the object has been garbage collected
     * then the get method will return null.
     */
    public class WeakRef
    {
        private var dic:Dictionary;

        /**
         * The constructor - creates a weak reference.
         * 
         * @param obj the object to create a weak reference to
         */
        public function WeakRef( obj:* )
        {
            dic = new Dictionary( true );
            dic[obj] = 1;
        }

        /**
         * To get a strong reference to the object.
         * 
         * @return a strong reference to the object or null if the
         * object has been garbage collected
         */
        public function get():*
        {
            for ( var item:* in dic )
            {
                return item;
            }
            return null;
        }
    }
}

In this Class, how they denote one as Weak Reference and one as Strong reference.

© Stack Overflow or respective owner

Related posts about flex

Related posts about actionscript