Skip to content
Mai Trinh
  • Android App
  • 15 min read

400 MB of bitmaps in a sleeping app: tracing Play vitals' "Bitmap memory in cached state" warning

An app sitting in the background still held over 400 MB of images, crossing Play vitals' bad behavior threshold. No crash, no stack trace, nothing on the emulator — only a heap dump on a real device found the culprit: 96 splash frames leaked through a location callback.

Mai Trinh

Software Engineer

On this page

A case study from a live Android app with over 60k downloads on the Play Store, about an issue that affects the user experience.

At a glance

  • Problem: ~400 MB of bitmaps still alive while the app sat in the background, over Play vitals' bad behavior threshold.
  • Cause: a Lottie splash made of 96 full-screen PNG frames, held by a static cache and leaked through a Play services location callback.
  • Result: background bitmaps 394–402 MB → 35–37 MB (≈ −91%), background Total PSS 704–709 → 254–324 MiB.

Overview

One day Play Console reported that the team's app had crossed the bad behavior threshold for Bitmap memory in cached state. The threshold is 400 MB.

"Cached state" is when the user has pressed HOME or switched to another app. Our process is still in RAM and has not been killed yet. The app draws nothing at that point, and yet it was holding more than 400 MB of images.

This is not an easy kind of bug:

  • No crash, no ANR, no stack trace to paste into a chat with an AI.
  • Does not reproduce on the emulator. Every number on the emulator looks "fine".
  • Never shows in the foreground. It only appears with the app in the background, on real devices, mostly low-RAM ones.
  • Silent consequences: an app using a lot of RAM in the background gets killed early. Users coming back face a cold start, and crossing a vitals threshold affects the app's visibility on the Play Store.

If you just ask an AI to "reduce bitmap memory", you get suggestions that make sense in theory: move images to drawable-nodpi, shrink Glide's cache, call clearMemory() in onTrimMemory. I tried them all. Almost none of them helped. What solved it was measuring in the right place, on the right device, then following the reference chain all the way to the GC root.

Root causes

Two main causes, plus two smaller sources.

Main cause: the splash animation is really a 96-frame PNG "video"

The splash screen's Lottie file weighs 13 MB. Opening the JSON showed it was not a vector animation but:

  • 96 base64-embedded 1080×1920 PNGs at 24 fps, each frame a full-screen image;
  • each frame decoded as ARGB_8888 takes 1080 × 1920 × 4 ≈ 7.9 MB;
  • 96 frames × 7.9 MB ≈ 760 MB if every frame gets drawn.

On a fast emulator Lottie only gets to decode 1 frame, so nothing shows. On a Samsung Galaxy A20s (2.8 GB RAM), the device decoded 45–50 frames during the 4-second animation — about 400 MB.

Why those frames were never released

Two layers held on to them:

  1. Lottie's static cache. LottieCompositionCache keeps the composition keyed by rawRes. The composition holds LottieImageAssets, and each asset holds its decoded bitmap.
  2. A leaked SplashActivity. This is the interesting part — see section 5.

As a result every decoded frame lived for the whole session, including while the app sat in the background. That is exactly what Play vitals measured.

Smaller sources (minor, but real)

  • Map markers: the marker-drawing function decoded the same icon again for every pin. About 60 pins produced about 100 duplicate bitmaps.
  • Mapbox MapView in the background: the map Activity was only stopped, not destroyed, so the map, style, GL resources and tile cache stayed alive. That alone held about 145 MiB of native heap.

Fixes (round 1)

  • 1.Move large images from drawable/ to drawable-nodpi/

    Measured effect
    None (explained in section 4)
  • 2.Call Glide.clearMemory() in onTrimMemory / onLowMemory

    Measured effect
    ~ −0.5 MB
  • 3.Shrink Glide's memory cache to 1.5 screens

    Measured effect
    No visible change
  • 4.Cache marker icons within each redraw

    Measured effect
    ~50 fewer bitmaps, native heap −15 to −35 MiB
  • 5.Destroy MapView in onStop, recreate it in onStart

    Measured effect
    Background PSS −50 MiB vs. baseline
  • 6.Release the Lottie frames when the splash is destroyed

    Measured effect
    ~400 MB → 35–37 MB of bitmaps

The first three rows are what "anyone would suggest". The last three only came from measuring.

Main fix: let go of the Lottie frames

In the layout, turn off composition caching:

<com.airbnb.lottie.LottieAnimationView
    ...
    app:lottie_cacheComposition="false"
    app:lottie_rawRes="@raw/splash_animation" />

When the Activity is destroyed, set every bitmap the composition holds to null:

override fun onDestroy() {
    if (::lottieView.isInitialized) {
        lottieView.cancelAnimation()
        // 96 full-screen frames, ~7.9 MB each. They must be released,
        // or they live for the whole session (cached state included).
        lottieView.composition?.images?.values?.forEach { it.bitmap = null }
    }
    super.onDestroy()
}
At first I only turned off the cache and called setImageDrawable(null). That worked in only half of the runs. The reason: the splash Activity itself was still being held, so the composition was still referenced. That was the clue that led to the leak in section 5.

Markers: decode once per redraw

val iconCache = HashMap<Int, Bitmap>()
points.forEach { point ->
    val icon = iconCache.getOrPut(point.iconRes) { decodeIcon(point.iconRes) }
    // ... create the annotation with the shared icon
}

Mapbox: really destroy it in the background

Mapbox's lifecycle plugin (v11) only moves the map to CREATED when the view is detached; it does not destroy it. reduceMemoryUse() helps, but only a little (−26 MiB). The thorough fix:

  • onStop: save the camera (center, zoom, bearing, pitch) and the MapView's position in its container, remove listeners, removeView(mapView), then mapView.onDestroy().
  • onStart: create a new MapView(context) in the same position, rerun the whole setup (style, route, markers, location puck), then restore the camera.
  • Skip all this when isChangingConfigurations.

To make this possible, the whole map setup had to move out of onCreateView into a reusable setUpMapView(mapView) function.

Measuring: the tools, and what actually matters

4.1. dumpsys meminfo is not enough

adb shell dumpsys meminfo <package>

This gives Total PSS, Native heap and Graphics. But:

  • since Android 9, resource and Glide images are usually hardware bitmaps, with their pixels in graphics memory;
  • on the emulator, Graphics: 0 and dumpsys gpu --gpumem returns nothing, so bitmaps are practically invisible.

So I counted bitmaps directly from a heap dump.

4.2. Heap dump + counting android.graphics.Bitmap

adb shell am dumpheap -g <package> /data/local/tmp/h.hprof   # -g: GC before dumping
adb pull /data/local/tmp/h.hprof
hprof-conv h.hprof h-conv.hprof

Then a small Python script (~80 lines, no libraries) parses the HPROF:

  1. find the android.graphics.Bitmap class;
  2. read the mWidth, mHeight, mDensity, mRecycled fields of each instance;
  3. sum width × height × 4 and print the largest bitmaps.
bitmaps=201 total_argb8888=402.0MB
  1080x1920 density=... 7.9MB
  1080x1920 density=... 7.9MB
  ... (repeated 45–50 times)

One look at this list says it all: dozens of bitmaps of the same 1080×1920 size, matching no image in res/. Those are the splash frames.

Android Studio Profiler can open heap dumps too. But when comparing many runs (original and fixed builds, 2–3 runs each, 4 states per run), a script gives comparable numbers right away and runs inside a shell loop.

4.3. A repeatable measuring scenario

Each scenario is a shell script using adb shell input tap/swipe and am start. For each state, the script records dumpsys meminfo and then a heap dump:

  1. Cold start, letting the splash actually run;
  2. open the map screen, take the map snapshot;
  3. browse images, take the image snapshot;
  4. HOME, wait 15 seconds, take the bg snapshot (this is the cached state);
  5. am send-trim-memory <package> BACKGROUND, take the bg + trim snapshot.

For a fair comparison, the original build was extracted with git archive into its own folder and built side by side with the fix branch. The two builds were installed over each other with adb install -r -d.

4.4. Lessons from measuring

  • The first hypothesis was wrong. I thought images in res/drawable/ (mdpi) were being upscaled to the screen density. But minSdk is 29, and ImageDecoder (API 28+) does not upscale drawables. The heap dump showed bitmap sizes exactly matching the source files, so moving to drawable-nodpi saved not a single byte.
  • The emulator lies. Every emulator number hovered around 35–50 MB of bitmaps. The 400 MB only appeared when measuring on a low-RAM, slow-CPU device.
  • PSS right after leaving a screen can still be high because the garbage has not been collected yet. Look at live bitmaps after GC, not just PSS.

The leak found while measuring

After setting bitmap = null on the Lottie frames, results were good one run and bad the next. The question: who still holds SplashActivity after its onDestroy?

I wrote two more heap dump scripts:

  • count_class.py: counts the live instances of a class;
  • path_to_root.py: a BFS from the GC roots to a target object, printing the shortest strong reference path (like LeakCanary, but offline on an hprof file).

The result:

LottieImageAsset.bitmap
  ← LottieComposition.images
  ← LottieDrawable.composition
  ← LottieAnimationView.lottieDrawable
  ← SplashActivity.lottieView
  ← SplashActivity
  ← LocationHelper.activity
  ← LocationHelper$locationCallback$1
  ← gms ListenerHolder (FusedLocationProvider)   ← GC root

The splash requested the location through a shared helper. That helper:

  • created the FusedLocationProviderClient from the Activity context;
  • used a LocationCallback written as an anonymous inner class, so it implicitly referenced the helper, and the helper referenced the Activity.

Even after removeLocationUpdates, Google Play services keeps the callback's ListenerHolder for a long time. The callback holds the helper, the helper holds the Activity, the Activity holds the LottieAnimationView, and at the end of the chain sit ~400 MB of frames.

This is the kind of leak that:

  • LeakCanary can catch, but only if you know to run the right flow on the right device;
  • code review almost never spots, because the code looks perfectly "correct": removeLocationUpdates is there, and it is called in onDestroy;
  • AI-written location code tends to produce exactly this pattern: object : LocationCallback() { ... } inside a class that holds an Activity.

Next fix: cutting the leak at the root

Two changes, both in the shared helper:

// 1. Client created from applicationContext, so it never holds the Activity
private val fusedLocationClient =
    LocationServices.getFusedLocationProviderClient(activity.applicationContext)

// 2. Callback is a static nested class holding the helper through a WeakReference
private val locationCallback = WeakLocationCallback(this)

private fun dispatchLocations(locations: List<Location>) {
    locations.forEach { onLocationChanged(it) }
}

private class WeakLocationCallback(owner: LocationHelper) : LocationCallback() {
    private val ownerRef = WeakReference(owner)
    override fun onLocationResult(result: LocationResult) {
        ownerRef.get()?.dispatchLocations(result.locations)
    }
}

On top of that, SplashActivity.onDestroy() now calls stopLocationUpdates() explicitly.

However long Play services keeps the callback now, all it holds is an empty object of a few bytes — the Activity no longer comes with it.

Verified again with path_to_root.py:

  • Path from GC root to SplashActivity

    Before
    through gms ListenerHolder → callback → helper → Activity
    After
    only ActivityThread.mNewActivities, a temporary framework queue that empties when the main thread goes idle
  • Live SplashActivity instances 15 s after HOME

    Before
    1 (holding ~400 MB of frames)
    After
    0
  • Bitmaps after HOME (main screen)

    Before
    37 MB
    After
    14.9 MB
  • PSS on entering the map screen

    Before
    740–748 MiB
    After
    383 MiB

Since this helper is used on every screen with location, fixing the leak benefits the whole app, not just the splash. The trade-off: every location feature needed a fresh smoke test.

Final results

Measured on a Samsung Galaxy A20s (Android 11, 720×1560, 2.8 GB RAM), debug build, same scenario. The pre-fix build ran 2 times, the fixed build 3 times.

Scenario: cold start (splash runs) → map screen (map snapshot) → view images, switch 2 items (image snapshot) → HOME, wait 15 s (bg snapshot) → send-trim-memory BACKGROUND (bg + trim snapshot). PSS from dumpsys meminfo (MiB; on Android 11 TOTAL PSS includes swap PSS), bitmaps from a heap dump after GC (count, total MB).

  • Map

    Metric
    Bitmaps
    Before fix (run 1 / run 2)
    198, 399 MB / 197, 392 MB
    After fix (run 1 / 2 / 3)
    98, 35 MB / 98, 35 MB / 97, 33 MB
  • Image

    Metric
    Total PSS
    Before fix (run 1 / run 2)
    752 / 778
    After fix (run 1 / 2 / 3)
    326 / 403 / 375
  • Image

    Metric
    Bitmaps
    Before fix (run 1 / run 2)
    201, 402 MB / 200, 394 MB
    After fix (run 1 / 2 / 3)
    103, 37 MB / 103, 37 MB / 102, 35 MB
  • Background (cached)

    Metric
    Total PSS
    Before fix (run 1 / run 2)
    704 / 709
    After fix (run 1 / 2 / 3)
    254 / 322 / 324
  • Background (cached)

    Metric
    Native heap
    Before fix (run 1 / run 2)
    394 / 487
    After fix (run 1 / 2 / 3)
    98 / 105 / 104
  • Background (cached)

    Metric
    Graphics
    Before fix (run 1 / run 2)
    31 / 31
    After fix (run 1 / 2 / 3)
    10 / 10 / 10
  • Background (cached)

    Metric
    Bitmaps
    Before fix (run 1 / run 2)
    201, 402 MB / 200, 394 MB
    After fix (run 1 / 2 / 3)
    98, 37 MB / 98, 37 MB / 97, 35 MB
  • Background + trim

    Metric
    Total PSS
    Before fix (run 1 / run 2)
    692 / 719
    After fix (run 1 / 2 / 3)
    263 / 313 / 314

Note: the fixed build's "map" snapshot (before the leak fix in section 6) sometimes still showed 740–748 MiB PSS. That snapshot was taken before the heap dump's forced GC, when the splash frames had been released but not yet collected. The heap dump right after showed only 33–35 MB of live bitmaps. After the leak fix, the same snapshot dropped to 383 MiB PSS, 116 MiB native, and background PSS to 302 MiB (1 run).

Map screen in the background, step by step (emulator, PSS MiB)

  • Background

    Baseline
    374–377
    + marker cache
    357–360
    + reduceMemoryUse()
    348–351
    + destroy MapView
    324–325
  • Background + trim

    Baseline
    382–387
    + marker cache
    363–373
    + reduceMemoryUse()
    351–355
    + destroy MapView
    316–319
Bitmaps in cached state went from ~400 MB to ~35 MB (about −91%), and background PSS dropped by more than half.

Final smoke test

The fixes above touch three risky areas: the splash screen lifecycle, the location helper shared across the app, and the map lifecycle (MapView destroyed and recreated every time the app goes to the background). So before release, the team ran one last smoke test on a build with all the fixes, focused on exactly these three areas rather than testing everything.

  • 1.Splash

    Scenario
    Cold start several times, signed in and signed out
    What must hold
    Animation plays to the end, navigation works, no crash
    Result
    Pass
  • 2.Splash

    Scenario
    Cold start → HOME → reopen the app
    What must hold
    No splash screen instance alive after going to the background
    Result
    Pass
  • 3.Location

    Scenario
    Grant location permission for the first time from the splash
    What must hold
    Permission dialog shows correctly, the app gets a location after granting
    Result
    Pass
  • 4.Location

    Scenario
    Deny location permission
    What must hold
    The app still reaches the main screen, no crash
    Result
    Pass
  • 5.Location

    Scenario
    Screens using location (nearby suggestions, location dot on the map)
    What must hold
    Location keeps updating as it did before the switch to WeakReference
    Result
    Pass
  • 6.Map

    Scenario
    Open the map → pan/zoom → HOME → reopen
    What must hold
    Map rebuilds with route, markers and location dot; camera returns to the same spot
    Result
    Pass
  • 7.Map

    Scenario
    Open another app screen over the map, then come back
    What must hold
    Map rebuilds, no blank screen, no crash
    Result
    Pass
  • 8.Map

    Scenario
    Switch back and forth with another app several times
    What must hold
    No crash, background memory does not grow round after round
    Result
    Pass
  • 9.Map

    Scenario
    Leave the map screen for good
    What must hold
    Activity closes cleanly, Mapbox logs "all resources were cleaned up"
    Result
    Pass
  • 10.Map

    Scenario
    Another screen sharing the same map fragment
    What must hold
    Displays and behaves as before
    Result
    Pass
  • 11.Images

    Scenario
    Screens with large images (onboarding, lists, image viewer)
    What must hold
    Images display correctly after shrinking Glide's cache and calling clearMemory() on trim
    Result
    Pass

A few things worth noting:

  • Cases 2 and 8 are "quantitative", not just checked by eye. Case 2 was verified with a heap dump (splash instances = 0). Case 8 ran 5 rounds in a row during measuring, with background PSS staying at 318–331 MiB, not growing.
  • Case 5 is the easiest one to miss. A callback holding its owner through a WeakReference means that if the helper is collected early, location updates silently stop with no error at all. You have to confirm location keeps working on a long-lived screen, not just that nothing crashes.
  • Screen rotation does not apply because the map screen is locked to portrait. The code still skips destroying the map when isChangingConfigurations, to be safe.

What's left

  • Replace the splash file. 96 full-screen PNG frames are a video in disguise. Use a vector Lottie, an animated WebP or a short video. Even with the current fix, the animation can still need up to ~760 MB while it plays, which can easily OOM on weak devices.
  • Measure again with a release build on a real device, then watch the metric in Play Console after release.
  • QA the MapView destroy/recreate flow on the other screens that share the map fragment.

Takeaways

  1. Vitals are not logs. There is no stack trace, so you have to rebuild the conditions yourself: a weak device, a cold start, going to the background.
  2. The emulator does not represent production, especially for graphics memory and animation timing.
  3. Measure first, fix second. The first three "best practices" I applied did almost nothing. Only the heap dump pointed at the real culprit.
  4. Go all the way to the GC root. Nulling the bitmaps only treated the symptom; the Activity leaking through a Play services callback was the root. Stopping at the first fix would have meant results that "sometimes work".
  5. Check assets, not just code. One 13 MB JSON exported by a designer can weigh more than all the code in the app.
  6. Callbacks handed to the system (Play services, system services, third-party SDKs) should not hold a strong reference to an Activity. Use applicationContext and WeakReference, and don't trust remove...() to let go right away.

AI helped a lot with writing the HPROF parsing scripts, building the adb scenarios and refactoring code. But the questions "where to measure, what to measure, and why this number doesn't add up" are still the engineer's job.

Appendix: detailed measurements

All numbers below are from debug builds. "Before fix" is the original commit built from git archive; "after fix" is the branch with the fixes. PSS and native heap are KB from dumpsys meminfo ÷ 1024 (MiB). Bitmaps are the sum of width × height × 4 over every live android.graphics.Bitmap in a heap dump after GC (MB).

A. Devices

  • Model

    Emulator
    Pixel 8 image, API 35
    Real device
    Samsung Galaxy A20s, Android 11
  • Screen

    Emulator
    1080×2400, 420 dpi
    Real device
    720×1560, 280 dpi
  • RAM

    Emulator
    (host machine)
    Real device
    2.8 GB
  • Graphics in meminfo

    Emulator
    always 0 (not measurable)
    Real device
    has values
  • Splash frames decoded

    Emulator
    1
    Real device
    45–50

B. Emulator: onboarding and main screen (live bitmaps)

  • Onboarding, sign-up screen (foreground)

    Before fix
    12 bitmaps, 45.7 MB
    After fix
    12 bitmaps, 45.7 MB
  • Onboarding, after HOME

    Before fix
    12 bitmaps, 45.7 MB
    After fix
    12 bitmaps, 45.7 MB
  • Main screen, foreground (run 1 / run 2)

    Before fix
    34.3 / 36.5 MB
    After fix
    34.3 / 38.5 MB
  • Main screen, after HOME

    Before fix
    33.9 / 36.1 MB
    After fix
    33.9 / 36.1 MB
  • Main screen, after TRIM_MEMORY_BACKGROUND

    Before fix
    33.9 / 36.1 MB
    After fix
    33.4 / 35.6 MB

Largest bitmaps on the onboarding screen (identical in both builds):

  • 1170×2442

    MB
    10.9
    Source
    onboarding background #1
  • 1170×2442

    MB
    10.9
    Source
    onboarding background #2
  • 1080×1920

    MB
    7.9
    Source
    not in res/, later identified as a splash frame
  • 1170×1155

    MB
    5.2
    Source
    onboarding background #3
  • 780×1628

    MB
    4.8
    Source
    onboarding background #4
  • 804×996

    MB
    3.1
    Source
    sign-up screen illustration
  • 1160×640

    MB
    2.8
    Source
    banner

Note: bitmap sizes match the source file sizes exactly, so there is no upscaling. This is the evidence that the drawable-nodpi hypothesis was wrong. All onboarding pages are alive at once (the ViewPager keeps every page) and are only released when the Activity closes.

C. Emulator: dumpsys meminfo (median of 3 runs, Total PSS)

This table shows why looking only at meminfo on the emulator reveals nothing: the two builds are almost identical.

  • Main screen (signed in), foreground

    Before fix
    238.6
    After fix
    244.1
  • Main screen, background

    Before fix
    220.9
    After fix
    219.8
  • Main screen, background + trim

    Before fix
    214.9
    After fix
    213.4
  • Onboarding, foreground

    Before fix
    235.7
    After fix
    233.7
  • Onboarding, background

    Before fix
    221.3
    After fix
    220.9
  • Onboarding, background + trim

    Before fix
    215.0
    After fix
    214.8

D. Emulator: map screen (Mapbox, ~60 markers), marker cache

Each build ran 2 times. Map: open the screen, wait 20 s. Image: open an image, switch 2 items.

  • Map

    Metric
    Total PSS
    Before fix (run 1 / 2)
    347.5 / 342.4
    Marker cache (run 1 / 2)
    335.9 / 331.5
  • Map

    Metric
    Native heap
    Before fix (run 1 / 2)
    141.6 / 137.6
    Marker cache (run 1 / 2)
    131.0 / 126.8
  • Map

    Metric
    Bitmaps
    Before fix (run 1 / 2)
    140, 45.2 MB / 138, 40.7 MB
    Marker cache (run 1 / 2)
    85, 40.7 MB / 85, 40.7 MB
  • Image

    Metric
    Total PSS
    Before fix (run 1 / 2)
    409.6 / 402.1
    Marker cache (run 1 / 2)
    367.9 / 375.0
  • Image

    Metric
    Native heap
    Before fix (run 1 / 2)
    195.5 / 188.2
    Marker cache (run 1 / 2)
    157.9 / 161.5
  • Image

    Metric
    Bitmaps
    Before fix (run 1 / 2)
    143, 51.1 MB / 141, 46.6 MB
    Marker cache (run 1 / 2)
    90, 53.5 MB / 92, 53.7 MB
  • Background

    Metric
    Total PSS
    Before fix (run 1 / 2)
    377.3 / 374.1
    Marker cache (run 1 / 2)
    357.1 / 359.9
  • Background

    Metric
    Native heap
    Before fix (run 1 / 2)
    165.2 / 161.5
    Marker cache (run 1 / 2)
    151.0 / 148.3
  • Background + trim

    Metric
    Total PSS
    Before fix (run 1 / 2)
    386.5 / 382.2
    Marker cache (run 1 / 2)
    373.2 / 363.2
  • Background + trim

    Metric
    Native heap
    Before fix (run 1 / 2)
    174.0 / 169.5
    Marker cache (run 1 / 2)
    168.7 / 151.4

Notes:

  • The bitmap count dropped by about 55 (≈ −40%) thanks to sharing marker icons.
  • Bitmaps don't change between "image" and the two background states: nothing is released on going to the background.
  • Native heap even grows after trim, because Mapbox keeps working in the background.
  • The main screen Activity is still alive underneath, so its 34–38 MB of bitmaps are counted here too.

E. Emulator: Mapbox, reduceMemoryUse() vs. destroying the MapView

  • Map, PSS

    Marker cache only
    335.9 / 331.5
    + reduceMemoryUse()
    330.7 / 334.3
    + destroy/recreate MapView
    331.4 / 330.6
  • Image, PSS

    Marker cache only
    367.9 / 375.0
    + reduceMemoryUse()
    366.4 / 362.9
    + destroy/recreate MapView
    366.7 / 362.0
  • Background, PSS

    Marker cache only
    357.1 / 359.9
    + reduceMemoryUse()
    351.2 / 348.1
    + destroy/recreate MapView
    324.4 / 325.1
  • Background, native heap

    Marker cache only
    151.0 / 148.3
    + reduceMemoryUse()
    146.8 / 144.4
    + destroy/recreate MapView
    119.7 / 121.3
  • Background, bitmaps

    Marker cache only
    —
    + reduceMemoryUse()
    91, 48.9 MB / 90, 46.7 MB
    + destroy/recreate MapView
    85, 46.4 MB / 85, 46.4 MB
  • Background + trim, PSS

    Marker cache only
    373.2 / 363.2
    + reduceMemoryUse()
    354.7 / 351.4
    + destroy/recreate MapView
    318.9 / 316.4
  • Background + trim, native heap

    Marker cache only
    168.7 / 151.4
    + reduceMemoryUse()
    149.4 / 146.9
    + destroy/recreate MapView
    114.0 / 112.1

Compared with the original in the background: 374–377 → 324–325 MiB (≈ −50 MiB); background + trim: 382–387 → 316–319 MiB (≈ −66 MiB). Foreground is almost unchanged, as expected, since the fix only acts in onStop.

What remains: ~115–120 MiB of native heap in the background, versus ~65 MiB with only the main screen. Part of it is Mapbox's process-wide state (tile store, render thread), which lives as long as the process.

F. QA of MapView destroy/recreate

  • Open settings / the image viewer dialog within the same Activity

    Result
    Activity is not stopped, the map stays as is
  • Open another app Activity on top, then close it

    Result
    Map destroyed ("all resources were cleaned up"), no crash
  • Switch to another app and back, 5 times in a row

    Result
    5 destroys, 5 new MapViews; background PSS stays at 318–331 MiB, no growth
  • Screen rotation

    Result
    Not applicable (Activity locked to portrait); the code still skips when isChangingConfigurations

G. Real device: before and after the leak fix

  • Path from GC root to SplashActivity

    Before leak fix
    gms ListenerHolder → callback → helper → Activity
    After leak fix
    only ActivityThread.mNewActivities (temporary)
  • Live SplashActivity instances 15 s after HOME

    Before leak fix
    1
    After leak fix
    0
  • Bitmaps after HOME (main screen)

    Before leak fix
    37 MB
    After leak fix
    14.9 MB
  • "map" snapshot (before forced GC)

    Before leak fix
    PSS 740–748, native 370–481 MiB
    After leak fix
    PSS 383, native 116 MiB
  • Full scenario, background

    Before leak fix
    PSS 254–324 MiB, 37 MB bitmaps
    After leak fix
    PSS 302 MiB, 37 MB bitmaps (1 run)

H. Summary

  • Live bitmaps

    Before
    394–402 MB
    After
    35–37 MB
    Change
    ≈ −91%
  • Bitmap count

    Before
    200–201
    After
    97–98
    Change
    ≈ −51%
  • Total PSS

    Before
    704–709 MiB
    After
    254–324 MiB
    Change
    ≈ −55 to −64%
  • Native heap

    Before
    394–487 MiB
    After
    98–105 MiB
    Change
    ≈ −75%
  • Graphics

    Before
    31 MiB
    After
    10 MiB
    Change
    ≈ −68%
  • Memory leak
  • Bitmap memory
  • Play vitals
  • Heap dump
  • Lottie
  • Mapbox

Keep reading

All posts