mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-26 22:43:05 +00:00
Use SoftReferences instead of WeakReferences for the eviction cache
This commit is contained in:
parent
d59e5ae9cf
commit
d704cb0b50
@ -4,7 +4,7 @@ import android.util.LruCache;
|
|||||||
|
|
||||||
import com.limelight.LimeLog;
|
import com.limelight.LimeLog;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.SoftReference;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class MemoryAssetLoader {
|
public class MemoryAssetLoader {
|
||||||
@ -21,12 +21,12 @@ public class MemoryAssetLoader {
|
|||||||
super.entryRemoved(evicted, key, oldValue, newValue);
|
super.entryRemoved(evicted, key, oldValue, newValue);
|
||||||
|
|
||||||
if (evicted) {
|
if (evicted) {
|
||||||
// Keep a weak reference around to the bitmap as long as we can
|
// Keep a soft reference around to the bitmap as long as we can
|
||||||
evictionCache.put(key, new WeakReference<>(oldValue));
|
evictionCache.put(key, new SoftReference<>(oldValue));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private static final HashMap<String, WeakReference<ScaledBitmap>> evictionCache = new HashMap<>();
|
private static final HashMap<String, SoftReference<ScaledBitmap>> evictionCache = new HashMap<>();
|
||||||
|
|
||||||
private static String constructKey(CachedAppAssetLoader.LoaderTuple tuple) {
|
private static String constructKey(CachedAppAssetLoader.LoaderTuple tuple) {
|
||||||
return tuple.computer.uuid+"-"+tuple.app.getAppId();
|
return tuple.computer.uuid+"-"+tuple.app.getAppId();
|
||||||
@ -41,7 +41,7 @@ public class MemoryAssetLoader {
|
|||||||
return bmp;
|
return bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
WeakReference<ScaledBitmap> bmpRef = evictionCache.get(key);
|
SoftReference<ScaledBitmap> bmpRef = evictionCache.get(key);
|
||||||
if (bmpRef != null) {
|
if (bmpRef != null) {
|
||||||
bmp = bmpRef.get();
|
bmp = bmpRef.get();
|
||||||
if (bmp != null) {
|
if (bmp != null) {
|
||||||
@ -54,7 +54,7 @@ public class MemoryAssetLoader {
|
|||||||
return bmp;
|
return bmp;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// The data is gone, so remove the dangling WeakReference now
|
// The data is gone, so remove the dangling SoftReference now
|
||||||
evictionCache.remove(key);
|
evictionCache.remove(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user