Aug 30th, 2010, 09:29 AM
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();
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?
Sep 7th, 2010, 03:52 AM
(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.
Sep 7th, 2010, 07:35 AM
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... :-)
Sep 7th, 2010, 08:52 AM
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
Sep 7th, 2010, 08:58 AM
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
Sep 13th, 2010, 04:32 AM
Thanks Roland, that one looks nice -- I'm gonna give it a try.
Sep 13th, 2010, 04:33 AM
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...