Image Loading (Coil & Glide) Flashcards
DATA › Networking
- What does the name Coil stand for, and what is it built on?
- Coil = Coroutine Image Loader. It is Kotlin-first and built on Coroutines, Okio, and a pluggable network layer (OkHttp or Ktor), with first-class Jetpack Compose support.
- Which Coil composable would you use to load a remote image in Compose, and what makes it async?
- AsyncImage. It launches the load on a coroutine tied to the composition, automatically cancelling when the composable leaves composition, and updates state without blocking the UI thread.
- What is the difference between AsyncImage and SubcomposeAsyncImage in Coil?
- AsyncImage uses a custom layout and is cheaper. SubcomposeAsyncImage uses subcomposition so you can render distinct loading/success/error composables and size based on result, but it is more expensive and cannot be used in lazy layout item sizing reliably.
- How does Glide know when to cancel or pause an image request?
- Glide.with() binds the request to the Activity/Fragment/View lifecycle. It pauses requests when the host stops and cancels/clears them when the view is recycled or the lifecycle is destroyed, preventing leaks and wasted work.
- Why is downsampling important and how do these libraries handle it?
- Decoding a full-resolution bitmap into a small view wastes memory and risks OutOfMemoryError. Both Coil and Glide automatically downsample/resize the decoded bitmap to the target view size using inSampleSize-style decoding.
- Describe the two levels of caching in Coil/Glide and their keys.
- A fast in-memory cache holds decoded bitmaps keyed by request (URL + size/transformations); a slower disk cache stores the original/encoded bytes keyed by URL. Memory is checked first, then disk, then network.
- In a RecyclerView, why might the wrong image appear in a row, and how is it prevented?
- Views are recycled, so a slow request can finish after the row is rebound. Loading via the target ImageView (Glide.into / Coil) cancels the previous request for that view, guaranteeing the latest bind wins.
- What is Glide's DiskCacheStrategy and what are the common options?
- It controls what gets written to disk: NONE, DATA (original bytes), RESOURCE (decoded/transformed), ALL (both), and AUTOMATIC (the default that picks intelligently based on the data source).
- Name a key architectural difference between Coil and Glide.
- Coil is Kotlin/coroutines-based, lighter weight, Compose-first, and supports Compose Multiplatform. Glide is older, Java-based, View/RecyclerView-oriented, uses a BitmapPool for aggressive bitmap reuse, and has a callback/RequestBuilder API.