Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Posts: 153
Registered: ‎10-26-2010
My Device: Bold 9900
My Carrier: AT&T
Accepted Solution

removing objects and events



If I do a removeChild on a button, does that remove the EventListener or do I have to do that first?



Accepted PlayBook Applications: Marmi-doos, BASIC, Run and Hide, SuperClip
Accepted OS4-7 SmartPhone App: KeepLightOn
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: removing objects and events

[ Edited ]

Good question.  I always do a removeEventListener on objects being removed.  It would be hard to test if the object generating the event is no longer there.  I do know in dealing with modules, that if there is still any kind of link associated with the module (eg event listeners), the the module does not totally unload.  My guess is that the listener will still be there.  I wish there was a "removeAllEventListeners()" to an object, but the safe bet is to remove the listeners before hand.


I think there is a call to return the number of listeners for a particular event, but you kind of want the opposite - number of event generators for a particular event method.


If some knows better, would love to know.

Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: removing objects and events

hey Harry,


according to the ASDocs:




using the removeChild() function simply sets the child objects parent property to null and "unlinks" it from the parent object by setting the value to null. so the object is still floating around just without a parent object and is therefore eligible for garbage collection. however if there is an eventlistener on the child being removed i do not think it can be garbage collected since there is still an active reference to that object even though it is not visible. i think it is confirmed by this line from the doc:

"...the object is garbage collected if no other references to the child exist."


its always good practice though to have your own dispose() function on a class that removes any listeners and sets the object to null. the garbage collection in actionscript isnt flawless so i think they recommend you reuse objects instead of trying to remove them and creating more later.

J. Rab (Blog) (Twitter)
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman