Skip to content

Conversation

copybara-service[bot]
Copy link

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.

…d 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.

PiperOrigin-RevId: 774983423
@sjudd
Copy link
Collaborator

sjudd commented Jun 24, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants