Skip to content

Release the map view and the controller when the map leaves the composition - #12

Merged
wf9a5m75 merged 2 commits into
developfrom
fix/mapview-teardown
Nov 8, 2026
Merged

wf9a5m75 merged 2 commits into
developfrom
fix/mapview-teardown

Conversation

@wf9a5m75

@wf9a5m75 wf9a5m75 commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

なぜ

地図が外れるとき、MapView は resumed の状態からいきなり onDestroy() されていました。

何を変えたか

  • 先に onPause / onStop を通してから破棄します(Activity がすでに済ませていれば飛ばします)。MapViewBase とローカルの effect のどちらが先に来ても、破棄は 1 回だけです。
  • state が自分で持っていた controller フィールド(接続時に入れて二度と消さない)をやめ、基底の接続中のコントローラを読むようにしました。MapViewBase が地図を破棄するときに外すので、アプリが持ち続ける state に古いコントローラとオーバーレイが残りません。

関連 PR(同じ修正の一式)

fix/mapview-teardown は次のリポジトリにまたがります。core → compose → 各プロバイダの順にマージしてください。プロバイダの変更は、core の MapViewState.detachController と、compose の MapViewBase(onDestroyMapView = …) / MapViewLifecycleOwner を使います。

検証

タブレット(HA26Z6JL)の example-app で確認しました。区画データ(約 10 万ポリゴン)はポリゴンのタイル描画が要るので、検証には、このブランチのコミットを feat/polygon-tiling / feat/overlay-on-added の上に一時的に cherry-pick したブランチ(test/teardown-on-tiling、push していません)を使っています。

  • 地図の切り替え(Boston の City parcels、MapLibre ⇄ Google): 毎回 am dumpheap -g で GC させて、GC 後のヒープを測りました。
    • 修正前: 292 → 489 MB と増え続け、5 回目の切り替えで OutOfMemoryError(512 MB)で落ちました。ヒープダンプでは、切り替え後も古い MapLibreViewController / GoogleMapViewController が残り、それぞれ 98,843 件の PolygonEntity を抱えていました。
    • 修正後: 24 回切り替えても、GC 後のヒープは 307〜309 MB で一定でした。Native alloc も増えていません。
  • 全プロバイダの巡回(11 種類、City parcels): 巡回後のヒープダンプに残った地図コントローラは、表示中の 1 個だけでした。PolygonEntity も表示中の地図の 98,843 件だけです。FATAL は 0 件でした。
  • 回転(横 → 縦 → 横): map-design ページでデフォルト以外のデザインを選んでから回しました。Google / HERE / Mapbox / ArcGIS 3D / ArcGIS 2D / MapLibre / TomTom / MapTiler / Longdo で、デザインとカメラが保たれ、プロセスも落ちませんでした。
  • 単体テスト・apiCheck: develop を起点に 12 モジュールで testDebugUnitTest と apiCheck を流しました。新しく足したテストはすべて通っています。失敗は次の 5 つで、どれも develop の時点で同じ理由で落ちています。
    • apiCheck: arcgis / maplibre / mappls / openmobilemaps
    • openmobilemaps の conformance テスト 1 件

確認できていないもの:

  • Mappls の回転: 検証用のビルドでは Mappls の認証設定が無く、初期化に失敗していました。
  • OpenMobileMaps の回転時のデザイン保持: example のデザイン選択 UI が OMM の state に対応していません(カメラの保持は確認済み)。

The MapView went straight from resumed to onDestroy() when the map left.
It is now wound down through onPause / onStop first (unless the Activity
already did), and released once whether MapViewBase or the local effect
gets there first.
The state kept its own controller field, set on attach and never cleared, so
a state the app keeps held the destroyed controller and every overlay of the
old map. It now reads the base's attached controller, which MapViewBase
detaches when the map is torn down.
@wf9a5m75
wf9a5m75 merged commit 4e63578 into develop Nov 8, 2026
2 checks passed
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