如何触发垃圾回收?

发布于 2024-12-08 10:05:02 字数 415 浏览 0 评论 0原文

有谁知道是否可以将垃圾收集应用于 AS3 中的新 StageVideo 组件?我尝试过没有成功!代码如下:

if ( this._stageVideo == null )
{
    this._stageVideo = stage.stageVideos[0];
    this._stageVideo.addEventListener(StageVideoEvent.RENDER_STATE, stageVideoStateChange);
}

尝试GC:

this._stageVideo = null;
this._stageVideo.removeEventListener(StageVideoEvent.RENDER_STATE, stageVideoStateChange);

Does anyone know if it's possible to apply garbage collection to the new StageVideo component in AS3? I have tried with no success! Code is below:

if ( this._stageVideo == null )
{
    this._stageVideo = stage.stageVideos[0];
    this._stageVideo.addEventListener(StageVideoEvent.RENDER_STATE, stageVideoStateChange);
}

Attempt at GC:

this._stageVideo = null;
this._stageVideo.removeEventListener(StageVideoEvent.RENDER_STATE, stageVideoStateChange);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离笑几人歌 2024-12-15 10:05:02
this._stageVideo = null;
this._stageVideo.removeEventListener(StageVideoEvent.RENDER_STATE, stageVideoStateChange)

我很惊讶它有效,它应该抛出异常,您应该首先删除事件侦听器,然后取消它的引用。

垃圾收集器不会在每次无效时启动,但如果您可以使用 Flash Builder 分析器,您可以尝试强制 GC,如果您想测试它,您可以将项目打包为 AIR,然后手动调用 GC。

如果您无法启动 LocalConnection 两次,则存在错误/功能,该错误/功能将调用 GC (http://www.nbilyk.com/flash-garbage-collection):

try {
    new LocalConnection().connect('foo');
    new LocalConnection().connect('foo');
} catch (e:Error) {}
this._stageVideo = null;
this._stageVideo.removeEventListener(StageVideoEvent.RENDER_STATE, stageVideoStateChange)

I'm surprised that it worked, it should throw an exception, you should first remove event listeners and then nullify it's reference.

Garbage collector does not start every time you nullify something, but if you can use Flash Builder profiler you can attempt to force GC, also if you want to test it out, you can package project as AIR, and call GC manually.

There is bug/feature that will invoke GC if you fail to start LocalConnection twice (http://www.nbilyk.com/flash-garbage-collection):

try {
    new LocalConnection().connect('foo');
    new LocalConnection().connect('foo');
} catch (e:Error) {}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文