PD:

On a second thought, I guess I misundertood the issue....

In this scenario:

private function listenerFunc(evt:Event):void {

}

someDispatcher.addEventListener( "someEvent", listenerFunc);


listenerFunc has a ref count of 1 before adding it to someDispatcher (and
that count will be 2 if I'm not using weak red), so even if I used a weak
ref and the GC runs, as long as listenerFunc is still on scope, it won't be
collected (because it's ref count would be 1, not 0).

Still, removeEventListener should be called explicitly in my opinion, but I
guess my previous post was wrong...


Cheers
Juan Pablo Califano

2008/8/17, Juan Pablo Califano <[EMAIL PROTECTED]>:
>
> >>>
> The last parameter - here set to true - makes the reference to your
> pageComplete function
> weak. Meaning if this reference is the only reference left to your removed
> object that object
> becomes ready for garbage collection.
> >>>
>
> If I'm not wrong, technically, the function object could be removed before
> the event even fires for the first time...
>
> I've read a lot of times about this "best practice", but I'm not really
> sure if its such a good idea. From Grant Skinner's articles, it seems that
> the rationale behind this is that since some people will forget to clean up
> properly after them, let's just use weak refs and let's trust out good
> luck -- at some point, the GC will do its job, so cross our fingers and hope
> it doesn't run "untimely" and screw us. Honestly, I don't think that could
> be rightfully called a best practice.
>
> It rather looks like a source of hard to find bugs. You're basically saying
> ok, I won't bother to clean up as I should, I'll just use a weak ref and
> hope for the best, i.e. that the GC won't run before an event I'm listening
> for is triggered and this "best practice" backfires at me.
>
> I could be wrong, though, but I'd like to hear what others thinks about it.
>
> Cheers
> Juan Pablo Califano
>
>
> 2008/8/15, dr.ache <[EMAIL PROTECTED]>:
>>
>> Hi Sander.
>>
>> When you add an EventListener you should in 99% set the weak reference
>> flag like this:
>>
>> mLoader.contentLoaderInfo.addEventListener( Event.COMPLETE,
>> pageComplete,false,0,true );
>>
>> The last parameter - here set to true - makes the reference to your
>> pageComplete function
>> weak. Meaning if this reference is the only reference left to your removed
>> object that object
>> becomes ready for garbage collection. Have a look in the as3 language
>> reference to learn more about it.
>>
>> Mark
>>
>>
>>
>> Sander Schuurman schrieb:
>>
>>> Hi cool list!
>>>
>>> I'm trying do build a generic structure of pages (swf's) loaded in a main
>>> swf, and unloading as well ofcourse.
>>> Now I'm trying to unload a loaded swf, with the famous Garbage
>>> Collection. But I'm not sure I'm doing it the right way. Hope you could
>>> point me in the right direction.
>>>
>>> My code:
>>>
>>> private function loadPage( qUrl :String ) :void
>>> {
>>>            var mLoader:Loader                    = new Loader();
>>>            var mRequest:URLRequest         = new URLRequest( qUrl );
>>>
>>>            mLoader.contentLoaderInfo.addEventListener( Event.COMPLETE,
>>> pageComplete );
>>>            mLoader.load( mRequest );
>>> }
>>> private function pageComplete( e :Event ) :void
>>> {
>>>            currentPage = e.currentTarget.content;
>>>
>>> currentPage.addEventListener( Page.PAGE_INIT, initPage );
>>>            currentPage.addEventListener( Page.GOTO_PAGE, gotoPage );
>>>
>>>            addChild(currentPage);
>>> }
>>> private function gotoPage( e :Event ) :void
>>> {
>>>            var nextPage = currentPage.gotoPage;
>>>
>>>            currentPage.removeEventListener( Page.PAGE_INIT, initPage );
>>>            currentPage.removeEventListener( Page.GOTO_PAGE, gotoPage );
>>>
>>>            var loader:Loader = Loader( e.target );
>>>            loader.unload();
>>>
>>>            loadPage( nextPage );
>>> }
>>>
>>> I'm not sure about the gotoPage method, if I can make a Loader object of
>>> the currentPage and unload it. Is it totally ready for the GC to be deleted?
>>> Thnx in advance.
>>>
>>> Sander
>>> _______________________________________________
>>> Flashcoders mailing list
>>> Flashcoders@chattyfig.figleaf.com
>>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>>
>>>
>>>
>>>
>>
>> _______________________________________________
>> Flashcoders mailing list
>> Flashcoders@chattyfig.figleaf.com
>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>
>
>
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to