views:

72

answers:

1

Hi Guys! As lots of people do, I use Map and SoftReference to create image cache to cache downloaded image.

In my implementation, the latest used bitmap will be putted at the first element of Map, so, when the image cache reach max cache size, the last element of the Map which is long-time not used will be removed, and SoftReference makes sure the bitmap will be recycled.

Here is the problem: how can I be sure the removed bitmap is not being used(like, draw on the screen, etc. etc.) when it is recycled. If the bitmap is being used, will SoftReference gc it? It is really difficult to understand what "Reachability" means in the api doc.

Thanks in advance!

A: 

If it is used by something other than your cache SoftReference, then it certainly is used with a hard reference (i.e. any variable or class member). Then the GC will not recycle it.

Kevin Gaudin
Ah, I got the point, thanks very much!
Tony