Results 1 to 7 of 7

Thread: LoadURLOperation: weak references for EventListeners -- any reason for this?

  1. #1
    Join Date
    Oct 2009
    Posts
    5

    Default LoadURLOperation: weak references for EventListeners -- any reason for this?

    In LoadURLOperation, weak references are used for adding the event listeners in init().

    The consequence for me is, that I can't use local variables for the operation instance, like this

    public function someFunc():void
    {
    var operation:IOperation = myService.someMethod();
    operation.addCompleteListener(completedHandler);
    }

    because the operation is likely to be be GC'd until the completedHandler is called.
    If my class uses more operations, the should be independent from each other, so local declaring "operation" as property is no solution. I'd have to biuld some complex container as a property where all the pending operations are manages, which is quite an overhead.

    Is this intended behaviour? Or am I missing something?

    Cheers,
    david

  2. #2
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    407

    Default

    Hey David,

    (sorry for the late reply, by the way)
    since the Flashplayer is singlethreaded your eventhandlers are guaranteed to be added and triggered before the IOperation might be gc'ed, the current code block will always be finished executing before the URLLoader's result has been processed.

    cheers,

    Roland

  3. #3
    Join Date
    Oct 2009
    Posts
    5

    Default

    Hi Roland,

    thanks for your reply!
    I'm not worried about my local var within the method someFunc(), but what happens with the URLLoader instance withing LoadURLOperation. This one seems to be gc'ed before it COMPLETE Event fires, which causes the Operations COMPLETE event not to fire.

    So it's the completedHandler (passed to operation.addCompleteListener) which is not called until I use strong references in init() of LoadURLOperation.

    That's at least what I was figuring out... :-)

    - David

  4. #4
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    407

    Default ?

    Hey David,

    that seems very strange to me, since the urlloader is being assigned to an instance variable internally, so the urloader can't be gc-ed before the operation.
    The _urlLoader variable is set to null though after it completes, but not before its data has been assigned to the operation's result property.
    The complete listener on your operation is added without a weakreference so this should prevent it from getting gc-ed though.

    I wil try and add some more unit tests for the LoadURLOperation when I have the time, I'm rather swamped at work right now though, so I'm not sure when I'll come round to it. I will get back to you though

    cheers,

    Roland

  5. #5
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    407

    Default btw....

    By the way,

    you might want to take a look at the OperationHandler helper class in Spring Actionscript 1.0, it can save you some time adding and removing event listeners on IOperations.

    OperationHandler API Docs link

    cheers,

    Roland

  6. #6
    Join Date
    Oct 2009
    Posts
    5

    Default

    Thanks Roland, that one looks nice -- I'm gonna give it a try.

    - David

  7. #7
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    407

    Default addendum

    Oh, and the OperationHandler contained a very silly bug in the errorhandler, its been fixed in the latest trunk... sorry about that, should have unit tested better, I know, I suck...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •