From 25e359595b4e1c02541a983d0d40f931b3fbdedc Mon Sep 17 00:00:00 2001 From: kalarina Date: Sun, 25 Oct 2026 12:29:31 +0200 Subject: [PATCH] Free decoded app icons once the UI is hidden The VPN service keeps the process alive in the background, and with it up to 256 icon bitmaps from the Apps tab. --- app/src/main/java/cc/skysparkle/sparkledns/AppsScreen.kt | 2 ++ app/src/main/java/cc/skysparkle/sparkledns/CrashLog.kt | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/app/src/main/java/cc/skysparkle/sparkledns/AppsScreen.kt b/app/src/main/java/cc/skysparkle/sparkledns/AppsScreen.kt index 048cd71..d567467 100644 --- a/app/src/main/java/cc/skysparkle/sparkledns/AppsScreen.kt +++ b/app/src/main/java/cc/skysparkle/sparkledns/AppsScreen.kt @@ -81,6 +81,8 @@ private class AppItem(val label: String, val packageName: String, val group: App // Decoded icons survive scrolling and tab switches instead of being rendered again every time private val IconCache = LruCache(256) +internal fun clearAppIconCache() = IconCache.evictAll() + // Shown right away when the tab opens again, while the list is read anew in the background. // Only touched on the main thread. private var lastAppList: List? = null diff --git a/app/src/main/java/cc/skysparkle/sparkledns/CrashLog.kt b/app/src/main/java/cc/skysparkle/sparkledns/CrashLog.kt index d5b6643..33d2c09 100644 --- a/app/src/main/java/cc/skysparkle/sparkledns/CrashLog.kt +++ b/app/src/main/java/cc/skysparkle/sparkledns/CrashLog.kt @@ -24,6 +24,13 @@ class SparkleApp : Application() { }, "startup-load").start() } + // The VPN keeps the process running long after the screens are gone; decoded app icons + // (up to about 9 MB) can be rendered again the next time the Apps tab opens + override fun onTrimMemory(level: Int) { + super.onTrimMemory(level) + if (level >= TRIM_MEMORY_UI_HIDDEN) clearAppIconCache() + } + // Debug builds only: logs disk and network access on the main thread, leaked closeables and the like private fun enableStrictMode() { StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build())