Improving memory management in ContactPhotoLoader.

What was happening was that during sync
photos would get loaded and softly retained.
The trouble was that GC would sometimes (often)
free them before they got retained by the
corresponding image view on the UI thread.

Change-Id: I6fd05e2761384f5c0a7c9ba470b718237b9fbbf1
diff --git a/src/com/android/contacts/list/ContactPhotoLoader.java b/src/com/android/contacts/list/ContactPhotoLoader.java
index 795366f..a6f40b6 100644
--- a/src/com/android/contacts/list/ContactPhotoLoader.java
+++ b/src/com/android/contacts/list/ContactPhotoLoader.java
@@ -82,6 +82,7 @@
         private static final int LOADED_NEEDS_RELOAD = 3;
 
         int state;
+        Bitmap bitmap;
         SoftReference<Bitmap> bitmapRef;
     }
 
@@ -324,12 +325,24 @@
             }
         }
 
+        softenCache();
+
         if (!mPendingRequests.isEmpty()) {
             requestLoading();
         }
     }
 
     /**
+     * Removes strong references to loaded bitmaps to allow them to be garbage collected
+     * if needed.
+     */
+    private void softenCache() {
+        for (BitmapHolder holder : mBitmapCache.values()) {
+            holder.bitmap = null;
+        }
+    }
+
+    /**
      * Stores the supplied bitmap in cache.
      */
     private void cacheBitmap(Object key, byte[] bytes) {
@@ -342,6 +355,7 @@
         if (bytes != null) {
             try {
                 Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length, null);
+                holder.bitmap = bitmap;
                 holder.bitmapRef = new SoftReference<Bitmap>(bitmap);
             } catch (OutOfMemoryError e) {
                 // Do nothing - the photo will appear to be missing