开发者

My Android game runs out of memory when it is closed and opened and couple times

I have an Android game that has an activity for the menu, and then another activity for the game that creates a SurfaceView and Thread to deal with canvas drawing and game logic. When you exit the game and start it up again too much or if you open and close the keyboard (thus restarting开发者_运维技巧 the activity), the game runs out of memory, usually when loading a bitmap:

java.lang.OutOfMemoryError: bitmap size exceeds VM budget

How can I keep all my images in memory without loading them again when the game changes state, or how can I release them from memory and let them reload when the game is restarted?


have you set android:launchMode in your manifest? If you haven't and your not explicitly handling returning to the original activity in onResume/onStart your likely getting multiple copies of your game activity running at the same time.

You can look at the various options for launchMode here


How are you loading and releasing the images currently?

Found this resource

"Try not to load the image into a byte array before passing it to the BitmapFactory but rather pass the InputStream directly to the BitmapFactory. There is a limit for the size of an image."


Your context may be leaking. This should help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜