Skip to content

Add MemoryBudgetManager sample and best practices - #515

Open
WSixx wants to merge 1 commit into
android:mainfrom
WSixx:feat/memory-budget-manager
Open

WSixx wants to merge 1 commit into
android:mainfrom
WSixx:feat/memory-budget-manager

Conversation

@WSixx

@WSixx WSixx commented Nov 16, 2026

Copy link
Copy Markdown

Summary

Adds a new :samples:performance:memory sample demonstrating MemoryBudgetManager (Android 17 QPR2 / API level 37.2, Build.VERSION_CODES_FULL.CINNAMON_BUN_2) and the recommended best practices for app memory budgets.

Changes

  • New module :samples:performance:memory:
    • Implemented MemoryBudgetSample using MemoryBudgetManager with:
      • Safe minor-SDK gating via MinSdkFullBox (Build.VERSION_CODES_FULL.CINNAMON_BUN_2) and @RequiresApi.
      • On-demand telemetry (processCurrentUsageBytes, packageCurrentUsageBytes, processBudgetBytes, packageBudgetBytes, handling LIMIT_IS_DISABLED) without continuous polling.
      • Discrete workload transitions (Gallery 96 MB mode, clearProcessBudget() for baseline restoration, tight 48 MB pressure test, idempotency, and IllegalArgumentException ceiling validation).
      • Lifecycle-aware OnOverBudgetListener registration (ON_START / ON_STOP) keeping callbacks fast/allocation-free and evicting a high-yield LruCache<String, Bitmap>.
    • Added samples/performance/memory/src/main/AndroidManifest.xml documenting <memory-budget> clauses and release-only best practices in comments (intentionally not merged globally into :app to avoid affecting unrelated debug/test samples).
    • Added module and topic documentation in samples/performance/README.md and samples/performance/memory/README.md (covering <memory-budget> attributes, src/release/AndroidManifest.xml, adb shell dumpsys activity processes, adb shell dumpsys meminfo, and utilities/android_mem_monitor.py).
  • Shared SDK gating (:shared):
    • Added MinSdkFullBox in MinSdkBox.kt to check Build.VERSION.SDK_INT >= Build.VERSION_CODES.BAKLAVA && Build.VERSION.SDK_INT_FULL >= minSdkFull.
  • App & root docs integration:
    • Registered :samples:performance:memory in settings.gradle.kts, app/build.gradle.kts, ApiSurface.kt, SampleDemo.kt, and root README.md.
    • Updated :app compileSdk to release(37) { minorApiLevel = 2 } (required by checkDebugAarMetadata for the new dependency).

Verification

  • ./gradlew spotlessCheck --init-script gradle/spotless-init.gradle.kts --no-configuration-cache — passed
  • ./gradlew :samples:performance:memory:lintDebug :shared:lintDebug :app:lintDebug :app:assembleDebug — passed (0 lint warnings/errors in :samples:performance:memory)

Fixes #514 🦕

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.

[FR]: Add MemoryBudgetManager sample

1 participant