glide icon indicating copy to clipboard operation
glide copied to clipboard

When an app is moved to background, onTrimMemory() will be called, and LruBitmapPool/MemoryCache will be trimmed. However, the app could keep running and will new bitmaps will be retired to MemoryCache and LruBitmapPool. This change limits the sizes of LruBitmapPool/MemoryCache to zero when the app is in background, and restore the sizes to normal when it's moved out of background.

Open copybara-service[bot] opened this issue 6 months ago • 1 comments

When an app is moved to background, onTrimMemory() will be called, and LruBitmapPool/MemoryCache will be trimmed. However, the app could keep running and will new bitmaps will be retired to MemoryCache and LruBitmapPool. This change limits the sizes of LruBitmapPool/MemoryCache to zero when the app is in background, and restore the sizes to normal when it's moved out of background.

copybara-service[bot] avatar Jun 24 '25 18:06 copybara-service[bot]

This is probably not a good idea. It'll cause a regression in performance for apps that would like to retain cached images in the background. The existing logic already decreases memory usage when the app is backgrounded, just not all the way to empty. That happens in onLowMemory

I don't think the atomic boolean here is useful these methods are all executed on the UI thread.

sjudd avatar Jun 24 '25 21:06 sjudd