使用 libgdx 时堆大小增加
在 libgdx 中,我曾经释放所有资源,例如纹理、音频资源以及世界对象。因为我的游戏中有很多纹理、绘图。纹理和声音资源的管理已通过调用 dispose() 释放。但问题仍然反复出现,并且堆大小不断增加。可能在某个时刻,如果超过最大大小,VM 就无法为进程分配内存,最终结果是 OutOfMemory。请帮助我摆脱这个。应用程序流
- 主页活动呈现到另一个扩展 AndroidApplication(应用程序侦听器)的活动。
- 我通过在此处初始化侦听器来在 onCreate() 中调用应用程序侦听器。
- 将一些游戏数据与上下文一起传递给侦听器。
In libgdx I used to release all resources such as textures, audio resources and also world object.As I have lot textures, drawbles in my game. Managing with textures and sound resources has been released by calling dispose(). But the problem still recurring and heap size is getting increased. Possibly at a certain point VM can not allocate the memory for process if it exceeds maximum size, finally result is OutOfMemory. Please help me to come out from this.App flow
- Home Activity renders to another Activity which extends AndroidApplication(application listener).
- In that i am calling application listener in onCreate() by initializing listener here.
- Passing some game data to listener along with context.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用的是 Bitmap 类,那么您可能需要检查在处置之前是否对每个类调用了回收。这解决了我的许多记忆问题。
关于 Bitmap 和 recycle() 的文档可以在这里找到
http://developer.android.com/reference/android/graphics/Bitmap.html
如果这没有帮助,那么您将不得不更多地描述应用程序的结构。也许您有错误的线程或正在消耗资源的东西。您使用什么工具来诊断您的记忆问题?
If you are using the Bitmap class, then you might want to check that you are calling recycle on each one before disposing. This fixed many of my memory problems.
Docs on Bitmap and recycle() can be found here
http://developer.android.com/reference/android/graphics/Bitmap.html
If that doesn't help then you are going to have to describe a bit more how the application is structured. Perhaps you have errant threads or something that are eating up resources. What tools are you using to diagnose your memory issues?