Laan's steps..

Feed Rss

as3 强制垃圾回收

10.28.2008, flash, by .

A very important thing to understand about the Garbage Collector in FP9 is that it’s operations are deferred. Your objects will not be removed immediately when all active references are deleted, instead they will be removed at some indeterminate time in the future. The GC uses a set of heuristics that look at RAM allocation and the size of the memory stack to determine when to run. As a developer, you must accept that fact that you will have no way of knowing when your inactive objects will get deallocated. You must also be aware that inactive objects will continue to execute indefinitely -until the GC deallocates it, so code will keep running.

as3的垃圾回收是一个自动的过程;当某个对象或变量不被任何引用时,avm并不是马上回收它的空间。而是移动到一个特定位置(垃圾场?),然后又回收机制处理。而至于什么时候处理,就得看情况了——avm觉得该处理了及会去处理下。adobe提供的类库是不提供主动垃圾回收功能。你不可能主动去控制它。不过可以通过一些别的方法去触发avm回收垃圾。有的事,不让我控制,那我就借助一些别的东西去控制。
try {
new LocalConnection().connect(‘lcname’);
new LocalConnection().connect(‘lcname’);
} catch (e:Error) {

}

上面这一段代码是可以触发avm进行垃圾回收处理。本人做了一个简单的测试,确实是如此啊。

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>