Actionscript 内存管理,垃圾收集 [英] Actionscript memory management, garbage collection

查看:27
本文介绍了Actionscript 内存管理,垃圾收集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个博客(和其他人)指出清理对象时,您应该在 dispose() 方法中将对象引用设置为 null.

This blog (and others) state that you should set object references to null inside your dispose() methods when cleaning up objects.

但是,Actionscript 3(带有 Flash Player 9)使用标记和清除 为您清除循环引用.所以我想知道:真的有任何理由将您的对象引用归零吗?

However, Actionscript 3 (with Flash Player 9) uses mark and sweep to clear out circular references for you. So I am wondering: is there really any reason to null out your object references?

推荐答案

我从不这样做 - 只要你做显而易见的事情:

I never do - as long as you do the obvious:

  • 中断对对象的所有引用(从数组中删除,将存储对象的变量设置为空,从显示列表中删除)
  • 删除所有事件监听器等

然后对象使用的内存可以随时覆盖.

Then the memory that was used by the object is available for overwriting at any time.

var ar:Array = [];
var mc:MovieClip = new MovieClip();

mc.addEventListener(MouseEvent.CLICK, pants);

ar[ar.length] = mc;
addChild(mc);

if(mc.parent) mc.parent.removeChild(mc); // not garbage collected
mc.removeEventListener(MouseEvent.CLICK, pants); // still not garbage collected
ar.splice(0, 1); // finally garbage collected

这篇关于Actionscript 内存管理,垃圾收集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆