coil-kt / coil

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

When to shutdown ImageLoader? #402

Closed mohamed-khaled-hsn closed 4 years ago

mohamed-khaled-hsn commented 4 years ago

Hi, First of all, amazing library it's really nicely done.

One I have a question

from docs:

Coil performs best when you create a single ImageLoader and share it throughout your app. This is because each ImageLoader has its own memory cache, bitmap pool, and network observer.

Unlike OkHttpClients, ImageLoaders must be shut down when finished with. This clears the observers held by the image loader and frees its memory imageLoader.shutdown()

I'm using DI to inject ImageLoader, and I initialize it on app start. where would be a good place to call imageLoader.shutdown()? since there is no callback for when the app is destroyed.

colinrtwhite commented 4 years ago

Thanks! You don't need to shut down your ImageLoader if you only create one instance and inject it throughout your app. When your app is killed it will automatically free your instance. I'll add a note to the docs about this.

It's important to call shutdown when you create more than one instance or if you create temporary instances.

mohamed-khaled-hsn commented 4 years ago

Great! I'll close this issue then.