I am pretty new to Android and have been developing a game. Every now and again I have users reporting out of memory exceptions
, which I find surprising since the bitmaps that I create are at most 200 kb in size. I call BitmapFactory.decodeResource()
whenever I create a new sprite
. Since my application is a zombie defense game, you could expect that I create sprites quite often.
Every time I create a sprite, I call decode resource to generate a bitmap. My question is if I was to only call decode resource at the start of each activitiy, and refer to the bitmap at package level, would this lessen the amount of memory placed on the VM Budget?
BitmapFactory.Options o=new BitmapFactory.Options();
o.inSampleSize = 4;
o.inDither=false; //Disable Dithering mode
o.inPurgeable=true; //Tell to gc that whether it needs free memory, the Bitmap can be cleared
myBitMap=BitmapFactory.decodeResource(getResources(),ID, o);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With