views:

368

answers:

3

I'm trying to reuse the HTTPService object in a flex app but I'm running into a problem. In the handler for ResultEvent.RESULT I'm removing the listener, but it isn't removed. I've have to catch the asyncToken from send() and attach a new property so I know what it's supposed to do in the handler.

I've set up an example here: http://www.152.org/flex/
You can right-click and view source.

Has anyone else run into an issue where listeners aren't removed? Should HTTPService not be reused?

A: 

There is no guarantee that the event listener will be removed. Try making it a weak event handler when installing it on your object. There's a better chance that Flex's GC will free this when you remove it.

dirkgently
I tried creating a weak reference and it's still not removing them..addEventListener(ResultEvent.RESULT, populateTilelist, false, 0, true);.removeEventListener(ResultEvent.RESULT, populateTilelist, false);
metric152
As I said, it's up to the VM to do GC. That's the right approach. However, the AS3 VM apparently finds some reference still pointing to this resource and hence does not remove the event handlers. Time to check the rest of the code, I believe?
dirkgently
+3  A: 

You cannot remove event listeners added in the mxml tag. livedocs says:

You can remove only event listeners that you added with the addEventListener() method in an ActionScript block. You cannot remove an event listener that was defined in the MXML tag

Define your HTTPService objects in actionscript (creationComplete of the app) and add event listeners using addEventListener method so that you can call removeEventListener on them to reuse.

Amarghosh
That's the approach I'm currently using. Events aren't removed when I call removeEventListener.
metric152
Read it again. Event listeners added thru mxml **cannot** be removed using removeEventListener. Period.
Amarghosh
Now I understand what you mean. I thought you meant if you used something inline on an MXML tag. Since I'm creating the HTTPService call in a .MXML file I can't use removeEventListener. I'll try that on monday.
metric152
Worked like a charm. I moved the HTTPService requests out to a wrapper file and I was able to remove the eventListeners. Thanks for your help.
metric152
This is a solution to a bug that exists in flex 3.4. It works fine in previous versions.
metric152
A: 

I came accross this problem today on an application that had been working well for several months. After serval hours of debugging, I found out that a recent upgrade in my flex compiler settings from 3.1 to 3.4 was the culprit. For now I have restored 3.1 as the compilation environment in order for my project to continue working.

In my opinion this is a major bug introduced sometime after Flex 3.1, I hope adobe fixes it soon. I reuse HTTPService all the time all over my code and this bug makes version 3.4 not workable for me.

Hope this helps.

Emil
good to know this know this was a bug and not a problem with my code. i'll have to update this example to reuse the service and submit it as a bug to adobe. thanks.
metric152
You are correct. I tested a tagged version of my code with flex 3.0 and it worked perfect. This is a new bug in the code. I'll submit this to adobe. Thanks for your help.
metric152
I've reported this as a bug to adobe.https://bugs.adobe.com/jira/browse/SDK-24847
metric152