fix(memory): release retired runtimes and idle download heap

This commit is contained in:
zarzet
2026-09-07 16:28:47 +07:00
parent c48406f5d0
commit e3f7817b29
4 changed files with 48 additions and 0 deletions
@@ -1395,6 +1395,7 @@ class DownloadService : Service() {
failed = counts.failed,
)
currentStatus = "finalizing"
releaseIdleDownloadMemory()
writeNativeWorkerSnapshot(
isRunning = false,
isPaused = false,
@@ -1702,6 +1703,7 @@ class DownloadService : Service() {
failed = counts.failed,
)
currentStatus = "finalizing"
releaseIdleDownloadMemory()
writeNativeWorkerSnapshot(
isRunning = false,
isPaused = false,
@@ -1718,6 +1720,16 @@ class DownloadService : Service() {
}
}
private fun releaseIdleDownloadMemory() {
try {
// All workers and album tagging have finished. Return unused Go
// heap without forcing a collection between individual tracks.
Gobackend.releaseMemory()
} catch (e: Exception) {
android.util.Log.w("SpotiFLAC", "Failed to release idle download memory: ${e.message}")
}
}
@Synchronized
private fun ensureWakeLock() {
val existingWakeLock = wakeLock