Hi 

I know it's good practise to clean up event listeners to improve on
performance. I see 2 ways of doing this:
- Explicitly clean up listeners (using removeEventListener(...))
- Specify 'useWeakRefrerences = true' when adding the event listener
(addEventListener(Event.ADDED_TO_STAGE, onAddedToStage, false, 0, true))

I usually implement both, explicitly removing events where I can. I
also don't trust the latter to be as effective as explicitly removing
listeners - is it as effective?

I have a bunch of item-renderers that have at least 4 event listeners.
I set up these events to use weak references. To be 100% safe I also
want to explicitly remove the listeners. So I listen for the
'removedFromStage' event, where I explicitly remove the listeners.

Enter problem ...
The 'removedFromStage' event is called when an item is initialized. 
Flex does some weird drawing initialization which ends firing
'removedFromStage' when the components initially load up. This results
in my event listeners being removed even before the component has
loaded and my item-renderers no longer work.

So, what is the solution? 
- Can I rely on the 'useWeakRef' attribute to clean up the listeners(I
have 100s of item-renderers)?
- Where could I explicitly remove the listeners if this is the correct
way of doing things?
- Why is 'removedFromStage' called at such an illogical point in the
creation of components?

Cheers
Tracy





Reply via email to