Fra*_*rth 2 flash actionscript garbage-collection memory-management actionscript-3
此博客(和其他人)声明在清理对象时应该在dispose()方法中将对象引用设置为null.
但是,Actionscript 3(使用Flash Player 9)使用标记和扫描来清除循环引用.所以我想知道:是否真的有理由废弃您的对象引用?
我从来没有 - 只要你做了明显的事情:
然后,对象使用的内存可随时覆盖.
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2573 次 |
| 最近记录: |