Android Image caching - how?

Viewed 3106

I think it is asked and asked before, but still, there are things I can't quite understand.

I have tried two different approaches:

  1. Keep all the images in memory, when certain limit is started to exceed, start removing them
  2. Let Android fix this with SoftReferences

In 2. it's just cleaning them up sometimes the second I allocate them! And I don't allocate too much - 30-40 images 50x50 pixels.

So I am sticking to one. The question is what is the limit?

  1. Can I get some reliable info from the device of how much exactly bitmap memory do I have left? I have done some research, watch DDMS values, it's just taking up more and more space (if I don't clean up) until it explodes. One moment there are only 200K left, next the system provides 2M more...
  2. I am currently using some heuristic decision, based on device model, or screen size. I think this is dead-end in the long run. Got memory exceptions on some phones, completely free on other.
  3. Is there a third solution, the right one?
5 Answers
Related