Image Loading (Coil & Glide) Interview Questions

DATA › Networking

Why do we use image loading libraries like Coil or Glide instead of loading bitmaps ourselves?

What a strong answer covers: They handle downloading off the main thread, memory and disk caching, downsampling to the target view size, bitmap pooling or reuse, cancelling requests when views are recycled or composables leave, lifecycle awareness, transformations, placeholders and errors. Writing that correctly yourself is hard and easy to get wrong with OutOfMemoryError.

How do you load large bitmaps without running out of memory?

What a strong answer covers: Decode only the size you need: read dimensions with inJustDecodeBounds, then set inSampleSize to downsample, or use ImageDecoder with a target size. A 4000x3000 photo is about 48 MB as ARGB_8888. Use RGB_565 where alpha isn't needed, cache wisely, recycle or reuse bitmaps, and let Coil or Glide do it based on the view size.

How does image caching work in Coil or Glide?

What a strong answer covers: There's a memory cache of decoded bitmaps keyed by URL plus size and transformations (an LRU sized as a fraction of available memory), and a disk cache of the downloaded or transformed data. A request checks memory, then disk, then network. Cache keys include the target size, so the same image at different sizes is cached separately.

Coil vs Glide: how would you choose, and what are the differences for a Compose app?

What a strong answer covers: Coil is Kotlin-first, coroutine-based, lightweight, has first-class Compose support (AsyncImage, rememberAsyncImagePainter) and Coil 3 is multiplatform. Glide is mature, highly optimised, with strong bitmap pooling and video frame support, mainly for Views, with an official Compose integration still in beta. For a new Compose or KMP app Coil is the usual choice; for an existing View app, Glide is fine.

A feed full of images is janky and uses too much memory. How would you investigate and fix it?

What a strong answer covers: Check the size images are loaded at (full-size images decoded for small thumbnails), that requests have a fixed size so downsampling works, that the server provides resized images or a CDN with size parameters, and that caches aren't too big. Look at allocations and GC in the Memory Profiler, decoding on the main thread, crossfades and transformations per frame, and whether requests are cancelled on scroll. Prefetch the next items' images with the right size.

Back to Image Loading (Coil & Glide)