动作的内存管理,垃圾收集 [英] Actionscript memory management, garbage collection
问题描述
此博客(及其他)状态你应该清理对象时设置对象引用空的处置()内的方法。
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)使用<一个href="http://www.adobe.com/devnet/flashplayer/articles/garbage_collection.html#articlecontentAdobe_numberedheader_1"相对=nofollow>标记和清理以清除循环引用你。所以我想知道:是真的有什么理由要空出你的对象引用
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:
- 在打破所有引用的对象(从阵列中删除,设置变量存储对象为null,从显示列表中删除)
- 删除所有事件侦听器等等
随后已使用的对象的内存可用于覆盖在任何时间。
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
这篇关于动作的内存管理,垃圾收集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!