jonny
jonny

Reputation: 9

Bitmap size exceeds VM budget after second load

This is driving me crazy. I have a game which has a bitmap as the background, this is big so I scale it down and this works fine. However when I navigate to another activity and then reload the game screen it crashes on drawing the background. I am calling recycle on all the bitmaps and setting them to null on onDestroy() but this doesn't help.

Any ideas and if not how can I debug the memory to see at which step its growing. I looked at getting the heap but nothing of any size is on there really.

Thanks.

Upvotes: 0

Views: 60

Answers (3)

When you jump from one activity A to another B, A doesnt finish and resources are still in memoery, there are 3 solutions for this.

  1. When calling activity B, you may finish activity A.
  2. Use WeakRefrences for bitmaps so the gc can rid of unused resouces and reload them onResume.
  3. remove refrences of the bitmaps onPause() and load them onResume()

Upvotes: 1

diordna
diordna

Reputation: 550

You can use MAT analyzer for checking memory issue, this link will help you

Upvotes: 2

Malachiasz
Malachiasz

Reputation: 7226

use bitmap.recycle() instantly after bitmap is not needed.

Upvotes: 0

Related Questions