如何触发垃圾回收?
有谁知道是否可以将垃圾收集应用于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很惊讶它有效,它应该抛出异常,您应该首先删除事件侦听器,然后取消它的引用。
垃圾收集器不会在每次无效时启动,但如果您可以使用 Flash Builder 分析器,您可以尝试强制 GC,如果您想测试它,您可以将项目打包为 AIR,然后手动调用 GC。
如果您无法启动 LocalConnection 两次,则存在错误/功能,该错误/功能将调用 GC (http://www.nbilyk.com/flash-garbage-collection):
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):