From d704cb0b500bab298451b22a1e24f80ccb6681b5 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Thu, 11 Jun 2020 19:10:43 -0700 Subject: [PATCH] Use SoftReferences instead of WeakReferences for the eviction cache --- .../com/limelight/grid/assets/MemoryAssetLoader.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/limelight/grid/assets/MemoryAssetLoader.java b/app/src/main/java/com/limelight/grid/assets/MemoryAssetLoader.java index 7feea570..aab6651b 100644 --- a/app/src/main/java/com/limelight/grid/assets/MemoryAssetLoader.java +++ b/app/src/main/java/com/limelight/grid/assets/MemoryAssetLoader.java @@ -4,7 +4,7 @@ import android.util.LruCache; import com.limelight.LimeLog; -import java.lang.ref.WeakReference; +import java.lang.ref.SoftReference; import java.util.HashMap; public class MemoryAssetLoader { @@ -21,12 +21,12 @@ public class MemoryAssetLoader { super.entryRemoved(evicted, key, oldValue, newValue); if (evicted) { - // Keep a weak reference around to the bitmap as long as we can - evictionCache.put(key, new WeakReference<>(oldValue)); + // Keep a soft reference around to the bitmap as long as we can + evictionCache.put(key, new SoftReference<>(oldValue)); } } }; - private static final HashMap> evictionCache = new HashMap<>(); + private static final HashMap> evictionCache = new HashMap<>(); private static String constructKey(CachedAppAssetLoader.LoaderTuple tuple) { return tuple.computer.uuid+"-"+tuple.app.getAppId(); @@ -41,7 +41,7 @@ public class MemoryAssetLoader { return bmp; } - WeakReference bmpRef = evictionCache.get(key); + SoftReference bmpRef = evictionCache.get(key); if (bmpRef != null) { bmp = bmpRef.get(); if (bmp != null) { @@ -54,7 +54,7 @@ public class MemoryAssetLoader { return bmp; } else { - // The data is gone, so remove the dangling WeakReference now + // The data is gone, so remove the dangling SoftReference now evictionCache.remove(key); } }