I have developed and launched a game called Bicycle Doodle GLD.

In this game, I load all the game resources at the initial loading scene. The game contains 24 levels, so only the resources that change for each level I don't load initially, but instead load at the level-select scene. Each level needs 5 to 15 terrain images that load during level selection time. There are the following scenes in the game: menu scene, level select scene, game play scene, and game over scene.

On each set of scene I call System.gc(), so memory clean up occur. My problem is that after playing a long time and changing scenes, the game suddenly closes without firing any message in debug.

I think memory becoming full is the reason. How do I fix this?


You need to profile your code and find what's taking up so much memory. Simply calling the garbage collection won't get rid of things that you've forgotten to stop using properly. Check out Traceview for a tool that comes with the SDK. Or search for your own Android profiler to find what's using your memory.

Once you have your memory usage statistics, you can find the parts of your code that use too much memory. Optimize those parts.


If you haven't already I would recommend looking at this video on memory management for Android apps. This gives a great overview of the Dalvik GC, and its basis in mark and sweep. It also shows some of the tools and abilities, even though its over a year old its a fantastic video.

Also, just calling System.gc() sends a suggestion to the Dalvik GC to try and release any marked memory for deletion. Of course at this point you may not have setup the rest of your program correctly to release resources, this is why as you continue to try and play it gets worse. In fact, the video specifically says you should avoid calling this method and just trust in the garbage collector, this is standard JAVA practice as well.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.