--- In flexcoders@yahoogroups.com, Mark Carter <c...@...> wrote:
<stuff snipped>

> Amy-28 wrote:
> > 
> >> As you can imagine, it keeps the implementation
> >> much simpler. No need for the ASyncToken. Just add new listeners 
> > each time a
> >> call is made. Everything is garbage collected..... Oh, hang on, 
> > what keeps a
> >> reference to the HTTPService?????
> > 
> > Good question.  What did you do with all the old eventListeners 
you 
> > were complaining about in your original post?
> > 
> 
> My current implementation has something like:
> 
> function save(xml:XML, successFunc:Function, 
failureFunc:Function):void {
>     var service:HTTPService = new HTTPService();
>     ...
>     service.addEventListener(ResultEvent.RESULT,
> function(evt:ResultEvent):void {
>         trace("Successfully saved XML");
>         successFunc();
>     });
>     service.send(); // called after the event listeners have been 
added :)
> }
> 
> That's it. The successFunc and failureFunc are only scoped to the 
calling
> code's method and so should be garbage collected when the service 
is garbage
> collected.
> 
> What I don't know is when the service is garbage collected? I'm 
assuming not
> before the result or fault event is fired!

My understanding is that anonymous functions _cannot_ get garbage 
collected unless you use weak references when you add them.  Which 
means there's a really good chance they'll get garbage collected 
before they get called.

HTH;

Amy

Reply via email to