Skip to main content

Android game programming - Heap issues


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={}

Source: Tips4allCCNA FINAL EXAM

Comments

  1. GC_FOR_MALLOC freed 104 objects / 504648 bytes in 47ms


    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.

    ReplyDelete
  2. 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:

    // Delete a texture
    int[] textures = { textureId };
    gl.glDeleteTextures(1, textures, 0);

    // Create new texture ...


    Or:

    int oldTextureId = textureId;
    ...
    // Create new texture
    ...
    // Delete texture
    int[] textures = { oldTextureId };
    gl.glDeleteTextures(1, textures, 0);

    ReplyDelete

Post a Comment

Popular posts from this blog

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex