Akshay Bhat Akshay Bhat - 1 year ago 122
Android Question

How to deallocate/free memory in android game

I created a 2d game for android using Bitmaps. After closing the game, android studio memory section shows that the memory is not de-allocated. So how can i de-allocate memory which is allocated for bitmaps.
I have a Bitmap array called

and i am initializing like

chopper[0] = BitmapFactory.decodeResource(getResources(), R.drawable.copter1);
chopper[1] = BitmapFactory.decodeResource(getResources(), R.drawable.copter2);
chopper[2] = BitmapFactory.decodeResource(getResources(), R.drawable.copter3);

So during closing the game i tried to free memory like


But it doesn't show free memory in android studio memory graph. Is it the way to free memory? If not how can i free the memory before closing the game.
Thanks in advance

Answer Source

Finally I Solved it. When exiting the game, I Made all my member objects null and also for the bitmaps i used bitmap.recycle() for each bitmap members (Referred Developers Website).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download