0
\$\begingroup\$

I am starting to get a pretty hefty amount of bitmaps in my 2d game for android. I load them all in 3 colors to save some memory but the thing is, I load all of them when "Start game" is pressed, even the ones that wont be used for another 5-6 levels. And There is no switching activities between levels, its all controlled using states to make the game smoother. I lack knowledge in memory-management so any kind of advice or preferred methods would be greatly appriciated. For example, if the bitmaps from level 1 never needs to be used again, do I need to delete them from memory manually or does the GC do that for me?

Also, does anyone know a good method for re-using bullets? I imagine just creating new ones will take a toll on memory? Cus Right now Im at 16mb heap when running my game, which makes no sense at all, even when I disable 80% of my game heap-size stays high, so Im obviously missing something.

\$\endgroup\$
1

1 Answer 1

1
\$\begingroup\$

Best design is to load and unload resources yourself and don't let the engine or library do this for you. This way you have all control.

Be sure to unload ALL resources you don't need in the current scene.

as for re-using bullets... I would instance a small bitmap for every bullet and unload it once it reached a certain distance or has, for example, left the screen (so it isn't visible)

Hope this helps.

\$\endgroup\$
4
  • \$\begingroup\$ Thanks! what is the best way to unload bitmaps? .recycle()? \$\endgroup\$
    – Green_qaue
    Commented Dec 27, 2013 at 21:36
  • \$\begingroup\$ Depends on what library you use. My experience comes from working with AndEngine where they had methods for that kind of operations. \$\endgroup\$
    – Dries
    Commented Dec 27, 2013 at 21:56
  • \$\begingroup\$ Using pure Java API. Want to learn from the ground up b4 I start using any helper libraries :) I can prob google my self an answer to this! :) \$\endgroup\$
    – Green_qaue
    Commented Jan 3, 2014 at 20:41
  • \$\begingroup\$ I can't find the exact implementation of unloading textures using pure java api in AndEngine source code so yeah, you'll probably have to google that. Or start a new question. \$\endgroup\$
    – Dries
    Commented Jan 3, 2014 at 20:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .