在 AS3 中强制垃圾收集? [英] Force Garbage Collection in AS3?

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

问题描述

是否可以在 ActionScript 3.0 中以编程方式强制运行完整的垃圾回收?

Is it possible to programmatically force a full garbage collection run in ActionScript 3.0?

假设我已经创建了一堆带有 eventListeners 的 Display 对象并且一些 DO 已经被删除,一些 eventListeners 已经被触发和删除等等......有没有办法强制垃圾收集运行和收集所有可以收集的东西?

Let's say I've created a bunch of Display objects with eventListeners and some of the DO's have been removed, some of the eventListeners have been triggered and removed etc... Is there a way to force garbage collection to run and collect everything that is available to be collected?

推荐答案

是的,这是可能的,但这通常是个坏主意.GC 应该比您应该更好地了解何时是运行的好时机,并且除了非常特殊的情况,比如您刚刚使用了 500MB 的内存并且您需要尽快将其取回,您不应该调用 GC自己.

Yes, it's possible, but it is generally a bad idea. The GC should have a better idea of when is a good time to run than you should, and except for a very specific case, like you just used 500MB of memory and you need to get it back ASAP, you shouldn't call the GC yourself.

在 Flash 10 中,您可以调用一个 System.gc() 方法(但请不要调用,请参见上文) - 请记住 System.gc() 仅适用于调试Flash 播放器 10+ 版本.

In Flash 10, there is a System.gc() method you can call (but please don't, see above) - keep in mind System.gc() only works in the debugging version of Flash player 10+.

在 Flash 9 中,有一种不受支持的方法可以通过奇怪的 LocalConnection 命令强制执行它,但它可能不适用于所有版本.请参阅 Grant Skinner 的这篇博文.

In Flash 9, there is an unsupported way to force it via an odd LocalConnection command, but it may not work in all versions. See this post by Grant Skinner.

这篇关于在 AS3 中强制垃圾收集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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