AS3:严重放缓
我正在开发一款 Flash 游戏,运行游戏一段时间后,帧速率大幅下降。屏幕上同时显示的影片剪辑并不多,但经常使用removeChild 和addChild 来替换影片剪辑。
如何测试内存泄漏等问题?在这方面有哪些好的 AS3 编程标准?
I'm working on a Flash game, and after running my game for a while there is a huge drop in frame rate. There aren't a lot of MovieClips onscreen at once, but MovieClips are being replaced using removeChild and addChild often.
How can one test for problems such as memory leaks? And what are some good AS3 programming standards on this matter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您似乎没有为垃圾回收准备
MovieClip
实例。 此线程可以对你非常有帮助。正确丢弃 MovieClip(或任何其他对象)时需要涵盖的一些基本内容是:
DisplayList
中删除对象(如果它是DisplayObject
)。这是通过您已经执行的操作来完成的,removeChild()
addEventListener()
时,请务必在不久的将来的某个地方添加一个姊妹removeEventListener()
。我可以提供的建议是在您的基类中包含对象是处理所有这些的方法,例如
remove()
或deconstruct()
。这是一个示例:
当您扩展此类并需要其他取消引用功能时,只需构建您的
deconstruct()
方法:It seems like you're not preparing your instances of
MovieClip
for garbage collection. This thread could be extremely helpful to you.Some of the basic things you want to cover when discarding a MovieClip (or any other Object) properly are:
DisplayList
(if it's aDisplayObject
). This is done via what you're doing already,removeChild()
addEventListener()
, be sure to somewhere in the very near future add a sisterremoveEventListener()
as well.A suggestion that I can offer is to have in the base class of your objects a method that handles all of this, eg
remove()
ordeconstruct()
.Here's an example:
And when you extend this class and need other dereferencing features, just build on your
deconstruct()
method:http://gskinner.com/talks/resource-management/
http://gskinner.com/talks/resource-management/