开发者

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

In flash AS3 Do I need remove childs, if I remove the 开发者_JS百科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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜