Adobe AIR - Garbage collection and system.gc()

社会主义新天地 提交于 2019-12-25 12:42:26

问题


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.

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

Thanks.


回答1:


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.

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.




回答2:


You don't need to call system.gc as it will be called automatically on idle cycles by the Flash runtime. If you call it yourself you might end up slowing down your application for no real gain.

When you don't need a BitmapData or a ByteArray anymore, just call BitmapData.dispose() or ByteArray.clear().



来源:https://stackoverflow.com/questions/7811228/adobe-air-garbage-collection-and-system-gc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!