feat(coil): Configure Coil-cache to no longer leak memory (#1031)
Configure Coil-cache to no longer leak memory, causing the app to slow down and eventually crash This configures the memory caching in the way presented by the official documentation at https://coil-kt.github.io/coil/image_loaders/
This commit is contained in:
parent
51c1f95791
commit
617c8788d5
1 changed files with 16 additions and 0 deletions
|
|
@ -20,6 +20,9 @@ import androidx.work.Configuration
|
|||
import androidx.work.WorkManager
|
||||
import coil3.ImageLoader
|
||||
import coil3.SingletonImageLoader
|
||||
import coil3.disk.DiskCache
|
||||
import coil3.disk.directory
|
||||
import coil3.memory.MemoryCache
|
||||
import coil3.network.okhttp.OkHttpNetworkFetcherFactory
|
||||
import coil3.request.allowRgb565
|
||||
import coil3.request.crossfade
|
||||
|
|
@ -266,6 +269,19 @@ class App : Application(), DefaultLifecycleObserver, SingletonImageLoader.Factor
|
|||
// SY <--
|
||||
}
|
||||
|
||||
memoryCache(
|
||||
MemoryCache.Builder()
|
||||
.maxSizePercent(context, 0.25)
|
||||
.build(),
|
||||
)
|
||||
|
||||
diskCache(
|
||||
DiskCache.Builder()
|
||||
.directory(context.cacheDir.resolve("image_cache"))
|
||||
.maxSizePercent(0.02)
|
||||
.build(),
|
||||
)
|
||||
|
||||
crossfade((300 * this@App.animatorDurationScale).toInt())
|
||||
allowRgb565(DeviceUtil.isLowRamDevice(this@App))
|
||||
if (networkPreferences.verboseLogging().get()) logger(DebugLogger())
|
||||
|
|
|
|||
Loading…
Reference in a new issue