Adobe AIR - 垃圾收集和 system.gc() [英] Adobe AIR - Garbage collection and system.gc()

查看:29
本文介绍了Adobe AIR - 垃圾收集和 system.gc()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Flash CS5 构建一个 Adob​​e AIR 桌面应用程序,该应用程序大量使用位图数据、字节数组和 base64 字符串.一段时间后,应用程序的内存使用量会翻倍.

I'm building an Adobe AIR desktop app with Flash CS5 that makes a lot of use of bitmapdata, bytearrays and base64 strings. After a while the memory usage of the app doubles.

此时是否建议使用 system.gc() 来释放内存,还是这种做法不好?

Is it recommended to use system.gc() to free memory at that point or is that bad practice?

谢谢.

推荐答案

system.gc 是 AIR 和 Flash 播放器中的仅调试功能.我认为最好的办法是回收位图数据和其他对象,如果可以避免 gc,如果不能,请在使用完后立即调用 bitmapdata.dispose() 和 bitmapdata = null.

system.gc is a debug only functionality in AIR and Flash player. I think the better thing is to recycle bitmapdata and other objects if you can to avoid gc, and if not call bitmapdata.dispose() and bitmapdata = null as soon as you are done with using them.

如果您的项目中在不同时间有相同大小的位图对象,您可以使用 BitmapData 的同一个实例对它们进行操作.这类似于 ItemRenderers 回收项目的方式,或者甚至其他平台(如 iOS 的 UITableViewController 回收/重用 UITableViewCell 的方式).垃圾回收不是灵丹妙药,应该在简单的可编程性比性能更重要时使用.

If you have bitmap objects of the same size at various times in your project, you can use the same instance of BitmapData to operate on them. This is similar to how ItemRenderers recycle items or how even other platforms like iOS's UITableViewController recycles/reuses UITableViewCell. Garbage collection is not panacea, it should be used when easy programmability is more important than performance.

这篇关于Adobe AIR - 垃圾收集和 system.gc()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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