代码之家  ›  专栏  ›  技术社区  ›  woodscreative

AS3快速有效地删除子级和侦听器并丢弃父级的方法

  •  0
  • woodscreative  · 技术社区  · 15 年前

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

    这是删除父项和子项的有效方法吗?

    3 回复  |  直到 15 年前
        1
  •  2
  •   Cadin    15 年前

    如果使用弱引用侦听器,则当您使对象无效时,侦听器不会阻止对其进行垃圾收集。

    useWeakReference是addEventListener调用中的第五个参数。

        2
  •  2
  •   alxx    15 年前

    AFAIK,无法枚举ActionScript中的侦听器。所以你必须写清理代码, removeEventListener 对称于 addEventListener .

        3
  •  0
  •   jdecuyper    15 年前

    View 递归地移除所有子级及其各自的侦听器。