Skip to content

Destroy the Android MapView when its map leaves the composition - #1179

Merged
davecraig merged 1 commit into
Scottish-Tech-Army:mainfrom
davecraig:main
Oct 22, 2026
Merged

davecraig merged 1 commit into
Scottish-Tech-Army:mainfrom
davecraig:main

Conversation

@davecraig

Copy link
Copy Markdown
Contributor

maplibre-compose 0.13 drives the MapView from LocalLifecycleOwner and only destroys it on that lifecycle's ON_DESTROY; leaving the composition just stops observing. Home stays on the back stack, so every time another screen was opened over it, its map was dropped without MapView.onDestroy, the only thing that frees MapLibre's native map. On a Samsung A52s each return to Home leaked about 2.7 MB of native heap, and the test farm's phones with the map on reached up to 2 GB.

The map now gets a lifecycle of its own that follows the screen's and is destroyed when the map leaves the composition, while maplibre-compose is still observing it. Over 40 returns to Home the native heap grew 6 MB instead of 74 MB, and every map was destroyed with its observer attached.

Claude-Session: https://claude.ai/code/session_01Ex6Fdp5ftuhE1ZEyhZb7WQ

maplibre-compose 0.13 drives the MapView from LocalLifecycleOwner and only
destroys it on that lifecycle's ON_DESTROY; leaving the composition just
stops observing. Home stays on the back stack, so every time another
screen was opened over it, its map was dropped without
MapView.onDestroy, the only thing that frees MapLibre's native map. On a
Samsung A52s each return to Home leaked about 2.7 MB of native heap, and
the test farm's phones with the map on reached up to 2 GB.

The map now gets a lifecycle of its own that follows the screen's and is
destroyed when the map leaves the composition, while maplibre-compose is
still observing it. Over 40 returns to Home the native heap grew 6 MB
instead of 74 MB, and every map was destroyed with its observer attached.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ex6Fdp5ftuhE1ZEyhZb7WQ
@davecraig
davecraig deployed to development October 22, 2026 10:59 — with GitHub Actions Active
@davecraig
davecraig deployed to development October 22, 2026 10:59 — with GitHub Actions Active
@davecraig
davecraig deployed to development October 22, 2026 10:59 — with GitHub Actions Active
@davecraig
davecraig deployed to development October 22, 2026 10:59 — with GitHub Actions Active
@davecraig
davecraig merged commit 8443d2b into Scottish-Tech-Army:main Oct 22, 2026
5 checks passed

This branch was successfully deployed

1 active deployment
development — d6d567d0 Deployed Oct 22, 2026 by davecraig via Run unit tests #1629
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.

1 participant