0
回答
先用强引用,后用软引用,这样设计的目的是什么啊?
终于搞明白,存储TCO原来是这样算的>>>   

谁能帮分析下这段代码,谢谢!

 public Bitmap getBitmapFromCache(String url) {
        // First try the hard reference cache
        synchronized (sHardBitmapCache) {
            final Bitmap bitmap = sHardBitmapCache.get(url);
            if (bitmap != null) {
                // Bitmap found in hard cache
                //下面这两句代码也不大懂,为什么不样写:if(url!=null) return  sHardBitmapCache.get(url);
                sHardBitmapCache.remove(url);               
                sHardBitmapCache.put(url, bitmap);
                return bitmap;

              }
         }

        // Then try the soft reference cache
        SoftReference<Bitmap> bitmapReference = sSoftBitmapCache.get(url);
        if (bitmapReference != null) {
            final Bitmap bitmap = bitmapReference.get();
            if (bitmap != null) {
                // Bitmap found in soft cache
                return bitmap;
            } else {
                // Soft reference has been Garbage Collected
                sSoftBitmapCache.remove(url);
            }
        }

        return null;
    }
 

<无标签>
举报
当空皓月
发帖于4年前 0回/108阅
顶部