Forum ActionScript 3.0 Garbaging objects

Problems and discussions relating to ActionScript 3.0 here.

Garbaging objects

Postby default0 » October 21st, 2010, 10:35 pm

Hey!

I have a small question about garbaging objects (MovieClips, TextFields and such).
I have coded a "scene" system that builds a new scene, pushes the movieclips, textfields etc into an array and then when the scene changes, it garbages all of those.
But sometimes listeners attached to the movieclips and textfields are not garbaged :!:
And this is where my problem lies.
Is there a smarter way than using "hasEventListener" for all kinds of event-types to garbage all listeners attached to a certain object?

Best regards
Try to play my Game: -->BlackGalaxy<--
User avatar
default0
 
Posts: 115
Joined: February 2nd, 2010, 6:46 pm
Location: Germany

Re: Garbaging objects

Postby azuanagames » October 21st, 2010, 11:52 pm

Look into weak references for the listeners:

Code: Select all
addEventHandler(Event, handler, false, 0, true);


Last parameter is useWeakReference:Boolean (default = false) — Determines whether the reference to the listener is strong or weak. A strong reference (the default) prevents your listener from being garbage-collected. A weak reference does not.
azuanagames
 
Posts: 157
Joined: April 29th, 2010, 10:59 pm

Re: Garbaging objects

Postby default0 » October 22nd, 2010, 9:54 am

azuanagames wrote:Look into weak references for the listeners:

Code: Select all
addEventHandler(Event, handler, false, 0, true);


Last parameter is useWeakReference:Boolean (default = false) — Determines whether the reference to the listener is strong or weak. A strong reference (the default) prevents your listener from being garbage-collected. A weak reference does not.


Thanks that really helped a lot !
Now I can just garbage the object without having to worry about listeners :)

Best regards
Try to play my Game: -->BlackGalaxy<--
User avatar
default0
 
Posts: 115
Joined: February 2nd, 2010, 6:46 pm
Location: Germany


Return to ActionScript 3.0