Conversation
onTrimMemory now coordinates BitmapCache, Coil product thumbs, and the preview working set (UI_HIDDEN soft-trim / BACKGROUND evict). Export releases those reconstructable caches when getMemoryInfo says the system is low or the Java heap has less than 64 MiB remaining. Co-authored-by: rosuH <hi@rosuh.me>
Post-14 only UI_HIDDEN and BACKGROUND remain meaningful trim levels. Co-authored-by: rosuH <hi@rosuh.me>
rosuH
force-pushed
the
cursor/android-memory-management-f96f
branch
from
September 4, 2026 00:52
8f3f8cd to
69f8f98
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reads Manage your app's memory against this photo-watermark app and applies the unused official strategies.
Already aligned (no change)
R8 minify + shrink, Coil-only UI thumbs,
inSampleSize/ RGB_565 thumbs,BitmapCachetrim, DEBUGProfilingManager, noService, nolargeHeap. The August Android 17 pass already covered most pillars.Gaps this PR closes
The article’s two unused code hooks were:
onTrimMemory— Coil product thumbs hold 30% of available memory and were not on the trim path.getMemoryInfo()before memory-intensive work —getAvailableMemory()existed with zero callers. Full-res export is that path.Also: preview trim ran on every trim level and always kept the focus Source, even when the process was a BACKGROUND kill candidate.
AndroidMemoryPressurenow coordinates three reconstructable caches:onLowMemoryExport calls
releaseReconstructableIfNeededfirst: if the system islowMemoryor remaining Java heap is under 64 MiB, those caches are dropped. The save is never skipped.Never
Bitmap.recycle()from a cache.Deliberately not applied
Hilt (ADR-0005 Koin), LeakCanary (privacy),
SparseArraysplit, activating the deadinBitmappool, closing Room on BACKGROUND, converting API 29+loadThumbnailto RGB_565.Full audit:
docs/superpowers/research/2026-08-30-manage-app-memory.mdTests
Robolectric (22/0):
AndroidMemoryPressureTest,AndroidPreviewSourceReuseTest,BitmapCacheTest,AndroidExportIntermediateReleaseTest.