coil-kt / coil

Image loading for Android and Compose Multiplatform.
https://coil-kt.github.io/coil/
Apache License 2.0
10.87k stars 669 forks source link

Getting strict mode warning for LeakedClosableViolation #1024

Closed MKevin3 closed 2 years ago

MKevin3 commented 2 years ago

D/StrictMode: StrictMode policy violation: android.os.strictmode.LeakedClosableViolation: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks. at android.os.StrictMode$AndroidCloseGuardReporter.report(StrictMode.java:1786) at dalvik.system.CloseGuard.warnIfOpen(CloseGuard.java:264) at java.io.FileInputStream.finalize(FileInputStream.java:487) at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:250) at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:237) at java.lang.Daemons$Daemon.run(Daemons.java:103) at java.lang.Thread.run(Thread.java:764) Caused by: java.lang.Throwable: Explicit termination method 'close' not called at dalvik.system.CloseGuard.open(CloseGuard.java:221) at java.io.FileInputStream.<init>(FileInputStream.java:168) at android.graphics.ImageDecoder.createFromFile(ImageDecoder.java:311) at android.graphics.ImageDecoder.access$700(ImageDecoder.java:169) at android.graphics.ImageDecoder$FileSource.createImageDecoder(ImageDecoder.java:526) at android.graphics.ImageDecoder.decodeDrawableImpl(ImageDecoder.java:1652) at android.graphics.ImageDecoder.decodeDrawable(ImageDecoder.java:1645) at coil.decode.ImageDecoderDecoder.decode(ImageDecoderDecoder.kt:188) at coil.intercept.EngineInterceptor$intercept$2.invokeSuspend(EngineInterceptor.kt:438) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)

When using an animated GIF for the image if that makes a difference. Using 1.4.0 version of the library

colinrtwhite commented 2 years ago

Duplicate of https://github.com/coil-kt/coil/issues/488. Unfortunately this is an issue in ImageDecoder itself that Coil can't work around because it never gets access to the FileInputStream that's allocated.