I've hit a few places in the past and will attempt to drudge them up, but no
warranties here.

How about a case where you create a timer as a local variable in a function
and add a weak listener. Since there are no strong references to the Timer I
beilieve it is eligible for garbage colleciton, and I'm pretty sure I've
seen that problem more than once.

public function setTimer():void
{
      var timer:Timer = new Timer(15000);
      timer.addEventListener(TimerEvent.TIMER,timerFired,false,0,true);
}

public function timerFired(event:TimerEvent):void
{
     //May never get called because Timer could be garbage collected before
firing
}

I think the safest way to do the above if you don't want to declare timer as
a member variable of the class is to use a strong reference and clean it up

public function setTimer():void
{
      var timer:Timer = new Timer(15000);
      timer.addEventListener(TimerEvent.TIMER,timerFired);
}

public function timerFired(event:TimerEvent):void
{
     event.target.removeEventListener(TimerEvent.TIMER,timerFired);
     //Yay! Should also make it here!
}

Typed that in GMail and unverified, as stated above, but may get the
conversation started at least

On Mon, Jul 14, 2008 at 11:28 PM, Josh McDonald <[EMAIL PROTECTED]> wrote:

>   That's a really good question, and one I'd very much like to know the
> answer to as well :)
>
> On Tue, Jul 15, 2008 at 2:08 PM, Boon Chew <[EMAIL PROTECTED]> wrote:
>
>>  Hi all,
>>
>> I have read posts that preached the goodness of weak references for event
>> listening, but have not read anything that suggests when you should use
>> strong reference over the weak one, and  the down side to using weak
>> references.
>>
>> Any ideas when being weak is not bad thing? :)
>>
>> - boon
>>
>> __
>>
>
>
>
> --
> "Therefore, send not to know For whom the bell tolls. It tolls for thee."
>
> :: Josh 'G-Funk' McDonald
> :: 0437 221 380 :: [EMAIL PROTECTED]
>  
>

Reply via email to