views:

37

answers:

1

In flash AS3 Do I need remove childs, if I remove the parent itseft?

If I remove childs first, then remove the parent object afterall
OR
If I just remove parent object

Will flash take same memory?

A: 

Well, if the children contains no reference variable or all children reference variable are set to null then removing the parent and setting the parent reference to null, will remove the children from memory also.But you have to manually remove listener attached to them. Using weak event listeners is pref-able in most situations as they are removed automatically when the objects or movie-clips are deleted by garbage collector, so u do not have to remove them manually. here is little example help u understand

var obj = new MainContainer(); obj.addEventListener(MouseEvent.CLICK, MainContainer_Clicked) addChild(Obj)

Now removing the Obj using removeChild(obj) will remove it from stage but not from memory. you have to set obj=null. And this goes same for MainContainer Children if it has. Now you have to manually remove the event listener attached to obj in this way

obj.removeEventListener(MouseEvent.CLICK, MainContainer_Clicked)

OR use weak event listener if you do not want it to remove yourself like this

obj.addEventListener(MouseEvent.CLICK, MainContainer_Clicked,false,0,true)

Read more about weak event listener here

http://gskinner.com/blog/archives/2006/07/as3_weakly_refe.html

Muhammad Irfan
http://stackoverflow.com/questions/2665721/as3-weak-listener-references-not-appropriate-during-initialization
Muhammad Irfan
I know about listeners, week listenert. Thank you.
Almas Adilbek