b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

softreference_referencequeue作用_java 虚引用(2)

电脑杂谈  发布时间:2017-05-28 01:05:00  来源:网络整理

LinkedHashMap.Entry<String, Bitmap> eldest) {

if (size() > HARD_CACHE_CAPACITY) {

// Entries push-out of hard reference cache are transferred to

// soft reference cache

mSoftBitmapCache.put(eldest.getKey(),

new SoftReference<Bitmap>(eldest.getValue()));

return true;

} else

return false;

}

};

/*

* SoftReference 指到的对象,即使没有任何 Direct Reference,也不会被清除。 一直要到 JVM 内存不足时且 没有

* Direct Reference 时才会清除,SoftReference 是用来设计 object-cache 之用的。softreference 不但可以把对象

* cache 起来,也不会造成内存不足的错误 (OutOfMemoryError)

*/

private final static ConcurrentHashMap<String, SoftReference<Bitmap>> mSoftBitmapCache = new ConcurrentHashMap<String, SoftReference<Bitmap>>(

HARD_CACHE_CAPACITY);

private final static Handler mPurgeHandler = new Handler();

private final static Runnable mPurgerRunnable = new Runnable() {

@Override

public void run() {

clearCache();

}

};

private static Bitmap getBitmapFromCache(String url) {

synchronized (mHardBitmapCache) {

final Bitmap bitmap = mHardBitmapCache.get(url);

if (bitmap != null) {

mHardBitmapCache.remove(url);

mHardBitmapCache.put(url, bitmap);

return bitmap;

}

}

SoftReference<Bitmap> bitmapReference = mSoftBitmapCache.get(url);

if (bitmapReference != null) {

final Bitmap bitmap = bitmapReference.get();

if (bitmap != null) {

return bitmap;

} else {

mSoftBitmapCache.remove(url);

}

}

return null;

}

public static void clearCache() {

mHardBitmapCache.clear();

mSoftBitmapCache.clear();

}

private static void resetPurgeTimer() {


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/ruanjian/article-49624-2.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...