开发者

AS3 quick and efficient way of removing children and listeners and discarding the parent

Is there a fast and efficient way of removing all children listeners etc from my app. If everything is contained in a displ开发者_开发百科ay object on the stage called View? I have lots of dynamically called children and their listeners do not get removed when I remove the View they reside in.

    public function _discard ():void
    {
        // Quick way to discard the view, remove children and listeners
        removeChild(View);
        View = null;
    }

Is this a valid way of removing the parent and children?


If you use weakly referenced listeners then the listeners will not prevent the objects from being garbage collected when you nullify them.

useWeakReference is the 5th parameter in the addEventListener call.


AFAIK, there is no way to enumerate listeners in ActionScript. So you have to write cleanup code, removeEventListener calls symmetrical to addEventListener.


alxx is right. there is no easy trick to solve this problem. In order to avoid removing manually all children/listeners, I would create a helper method that receives a View and recursively removes all children and their respective listeners.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜