Android游戏编程-堆问题
我在一家小型 Android 游戏开发公司工作,目前我遇到了一个问题。我正在运行一台非常标准的 Windows 7 x64 机器,带有 Eclipse 和 Android SDK。
我正在阅读程序的 LogCat 输出,想知道为什么我的游戏甚至不显示。我很快看到所有堆都在增长,并认为我可能有太多纹理/太大的纹理等。我查明了纹理加载的问题,然后我开始使用 DDMS 并注意到我的堆不会增长超过 19MB。我剪掉了一些纹理并尝试再次构建并运行。令我震惊的是,堆的大小始终不会超过 6.6MB。有人有什么建议吗?
tl;dr:我的堆增长到 19MB,然后失败了,因此我取出了内存消耗更大的纹理,以将其保持在堆中的 19MB 以下,现在我的堆不会增长超过 6.6MB。
:当取出更大的纹理时,logcat 输出:
08-19 19:19:53.744: DEBUG/dalvikvm(4699): GC_FOR_MALLOC freed 91 objects / 514016 bytes in 49ms 08-19 19:19:54.184: DEBUG/dalvikvm(4699): GC_FOR_MALLOC freed 104 objects / 494088 bytes in 48ms 08-19 19:19:54.404: WARN/ActivityManager(59): Launch timeout has expired, giving up wake lock! 08-19 19:19:54.764: DEBUG/dalvikvm(4699): GC_FOR_MALLOC freed 85 objects / 384664 bytes in 49ms 08-19 19:19:54.935: WARN/ActivityManager(59): Activity idle timeout for HistoryRecord{4612eec8 com.wickeyware.zombiearcher.android/.AndroidGame} 08-19 19:19:55.234: DEBUG/dalvikvm(4699): GC_FOR_MALLOC freed 104 objects / 504648 bytes in 47ms 08-19 19:19:55.875: DEBUG/dalvikvm(4699): GC_FOR_MALLOC freed 85 objects / 505712 bytes in 55ms 08-19 19:19:56.905: DEBUG/dalvikvm(4699): GC_FOR_MALLOC freed 104 objects / 522392 bytes in 50ms 08-19 19:19:57.535: DEBUG/dalvikvm(4699): GC_FOR_MALLOC freed 56 objects / 388896 bytes in 50ms 08-19 19:19:57.695: INFO/WindowManager(59): WIN DEATH: Window{4606a8a0 com.android.launcher/com.android.launcher2.Launcher paused=false} 08-19 19:19:57.705: INFO/ActivityManager(59): Process com.android.launcher (pid 4669) has died. 08-19 19:19:57.825: INFO/ActivityManager(59): Low Memory: No more background processes. 08-19 19:19:57.865: INFO/dalvikvm(4699): dvmDdmHandleHpsgChunk(when 1, what 0, heap 0) 08-19 19:19:58.575: DEBUG/ddm-heap(4699): Heap GC request 08-19 19:19:58.685: DEBUG/dalvikvm(4699): GC_EXPLICIT freed 48 objects / 313440 bytes in 106ms 08-19 19:20:01.015: INFO/ActivityManager(59): Process jp.co.omronsoft.openwnn (pid 4677) has died. 08-19 19:20:01.095: WARN/ActivityManager(59): Scheduling restart of crashed service jp.co.omronsoft.openwnn/.OpenWnnJAJP in 5000ms 08-19 19:20:01.106: INFO/ActivityManager(59): Low Memory: No more background processes. 08-19 19:20:03.105: INFO/ActivityManager(59): Process com.wickeyware.zombiearcher.android (pid 4699) has died. 08-19 19:20:03.155: INFO/WindowManager(59): WIN DEATH: Window{46138b68 SurfaceView paused=false} 08-19 19:20:03.275: INFO/WindowManager(59): WIN DEATH: Window{4612d530 com.wickeyware.zombiearcher.android/com.wickeyware.zombiearcher.android.AndroidGame paused=false} 08-19 19:20:03.425: INFO/ActivityManager(59): Start proc com.android.launcher for activity com.android.launcher/com.android.launcher2.Launcher: pid=4710 uid=10025 gids={} 08-19 19:20:03.425: INFO/ActivityManager(59): Low Memory: No more background processes. 08-19 19:20:03.775: INFO/UsageStats(59): Unexpected resume of com.android.launcher while already resumed in com.wickeyware.zombiearcher.android 08-19 19:20:03.904: INFO/ActivityThread(4710): Publishing provider com.android.launcher2.settings: com.android.launcher2.LauncherProvider 08-19 19:20:04.005: DEBUG/dalvikvm(4710): GC_EXTERNAL_ALLOC freed 985 objects / 73440 bytes in 58ms 08-19 19:20:04.465: WARN/InputManagerService(59): Got RemoteException sending setActive(false) notification to pid 4699 uid 10036 08-19 19:20:04.984: INFO/ActivityManager(59): Displayed activity com.android.launcher/com.android.launcher2.Launcher: 1703 ms (total 20584 ms) 08-19 19:20:06.124: INFO/ActivityManager(59): Start proc jp.co.omronsoft.openwnn for service jp.co.omronsoft.openwnn/.OpenWnnJAJP: pid=4718 uid=10023 gids={}
I work for a small Android game development company, and currently I'm having an issue. I'm running a pretty standard windows 7 x64 machine, with Eclipse and the Android SDK.
I was reading the LogCat output for my program, wondering why my game wouldn't even show up. I quickly saw all of the heap growing, and thought I may have too many textures/too big of textures, etc. I pinpointed the problem to texture loading, then I started using DDMS and noticed my heap won't grow above 19MB. I cut out a couple textures and tried to build and run again. To my shock, the heap wouldn't grow past 6.6MB, consistently. Does anyone have any suggestions?
tl;dr: My heap was growing to 19MB then failing, so I took out textures that were more memory-expensive to keep it under 19MB in the heap, and now my heap won't grow past 6.6MB.
EDIT: logcat ouput when bigger textures are taken out:
08-19 19:19:53.744: DEBUG/dalvikvm(4699): GC_FOR_MALLOC freed 91 objects / 514016 bytes in 49ms 08-19 19:19:54.184: DEBUG/dalvikvm(4699): GC_FOR_MALLOC freed 104 objects / 494088 bytes in 48ms 08-19 19:19:54.404: WARN/ActivityManager(59): Launch timeout has expired, giving up wake lock! 08-19 19:19:54.764: DEBUG/dalvikvm(4699): GC_FOR_MALLOC freed 85 objects / 384664 bytes in 49ms 08-19 19:19:54.935: WARN/ActivityManager(59): Activity idle timeout for HistoryRecord{4612eec8 com.wickeyware.zombiearcher.android/.AndroidGame} 08-19 19:19:55.234: DEBUG/dalvikvm(4699): GC_FOR_MALLOC freed 104 objects / 504648 bytes in 47ms 08-19 19:19:55.875: DEBUG/dalvikvm(4699): GC_FOR_MALLOC freed 85 objects / 505712 bytes in 55ms 08-19 19:19:56.905: DEBUG/dalvikvm(4699): GC_FOR_MALLOC freed 104 objects / 522392 bytes in 50ms 08-19 19:19:57.535: DEBUG/dalvikvm(4699): GC_FOR_MALLOC freed 56 objects / 388896 bytes in 50ms 08-19 19:19:57.695: INFO/WindowManager(59): WIN DEATH: Window{4606a8a0 com.android.launcher/com.android.launcher2.Launcher paused=false} 08-19 19:19:57.705: INFO/ActivityManager(59): Process com.android.launcher (pid 4669) has died. 08-19 19:19:57.825: INFO/ActivityManager(59): Low Memory: No more background processes. 08-19 19:19:57.865: INFO/dalvikvm(4699): dvmDdmHandleHpsgChunk(when 1, what 0, heap 0) 08-19 19:19:58.575: DEBUG/ddm-heap(4699): Heap GC request 08-19 19:19:58.685: DEBUG/dalvikvm(4699): GC_EXPLICIT freed 48 objects / 313440 bytes in 106ms 08-19 19:20:01.015: INFO/ActivityManager(59): Process jp.co.omronsoft.openwnn (pid 4677) has died. 08-19 19:20:01.095: WARN/ActivityManager(59): Scheduling restart of crashed service jp.co.omronsoft.openwnn/.OpenWnnJAJP in 5000ms 08-19 19:20:01.106: INFO/ActivityManager(59): Low Memory: No more background processes. 08-19 19:20:03.105: INFO/ActivityManager(59): Process com.wickeyware.zombiearcher.android (pid 4699) has died. 08-19 19:20:03.155: INFO/WindowManager(59): WIN DEATH: Window{46138b68 SurfaceView paused=false} 08-19 19:20:03.275: INFO/WindowManager(59): WIN DEATH: Window{4612d530 com.wickeyware.zombiearcher.android/com.wickeyware.zombiearcher.android.AndroidGame paused=false} 08-19 19:20:03.425: INFO/ActivityManager(59): Start proc com.android.launcher for activity com.android.launcher/com.android.launcher2.Launcher: pid=4710 uid=10025 gids={} 08-19 19:20:03.425: INFO/ActivityManager(59): Low Memory: No more background processes. 08-19 19:20:03.775: INFO/UsageStats(59): Unexpected resume of com.android.launcher while already resumed in com.wickeyware.zombiearcher.android 08-19 19:20:03.904: INFO/ActivityThread(4710): Publishing provider com.android.launcher2.settings: com.android.launcher2.LauncherProvider 08-19 19:20:04.005: DEBUG/dalvikvm(4710): GC_EXTERNAL_ALLOC freed 985 objects / 73440 bytes in 58ms 08-19 19:20:04.465: WARN/InputManagerService(59): Got RemoteException sending setActive(false) notification to pid 4699 uid 10036 08-19 19:20:04.984: INFO/ActivityManager(59): Displayed activity com.android.launcher/com.android.launcher2.Launcher: 1703 ms (total 20584 ms) 08-19 19:20:06.124: INFO/ActivityManager(59): Start proc jp.co.omronsoft.openwnn for service jp.co.omronsoft.openwnn/.OpenWnnJAJP: pid=4718 uid=10023 gids={}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是垃圾收集器的触发。不幸的是,没有任何来源,这里没有人能够帮助你。
但是,看起来您实例化了太多对象,并且垃圾收集器几乎不断触发。
This is the garbage collector firing. Unfortunatly, without any source, nobody here will be able to help you.
But, it looks like you are instantiating WAY too many objects and the garbage collector is almost constantly firing.
你好。我不太确定我的答案是否正确,但我也遇到了类似的问题。
问题在于为某些对象创建新纹理。我做了太多次,结果都是类似的异常。我的解决方案:在为对象设置新纹理之前,我删除了旧纹理。
例如:
或者:
Hello. I am not pretty sure that my answer is correct, but I had a similar problem.
The problem was in the creation of a new texture for some object. I did it too many times and the result was a similar exception. My solution: before I set a new texture to the object, I deleted the old one.
For example:
Or: