Repository navigation
Release the map view and the controller when the map leaves the composition - #21
Merged
Merged
Conversation
Only the Activity's real ON_DESTROY destroyed the MapView, so a provider switch left it alive with the controller it reaches. It is now stopped and destroyed through MapViewBase's onDestroyMapView, once.
Mapbox's lifecycle plugin registers component callbacks on the Activity and observes the view tree's lifecycle, and lets go only when that lifecycle is destroyed; MapView.onDestroy() does not undo it. Under the Activity's lifecycle every MapView the user switched away from (and through its click listeners the controller) stayed until the Activity went. The MapView now gets a MapViewLifecycleOwner, ended in onDestroyMapView: the plugin then stops and destroys it and unregisters what it registered.
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. The polygon conductor's destroy() clears its polygon and outline managers, as core's PolygonController now does.
This was referenced Nov 8, 2026
Merged
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.
なぜ
MapView を破棄していたのは Activity の本当の ON_DESTROY のときだけで、プロバイダを切り替えると MapView がコントローラと一緒に残っていました。
さらに Mapbox のライフサイクルプラグインは、Activity に ComponentCallbacks を登録し、ビューツリーのライフサイクルを observe します。放すのはそのライフサイクルが destroy されたときだけで、
MapView.onDestroy()では外れません。何を変えたか
MapViewBaseのonDestroyMapViewから 1 回だけ stop して破棄します。MapViewLifecycleOwnerを渡し、onDestroyMapViewで終わらせます。プラグインはそれを見て MapView を止めて破棄し、登録したものを外します。controllerフィールド(接続時に入れて二度と消さない)をやめ、基底の接続中のコントローラを読むようにしました。MapViewBaseが地図を破棄するときに外すので、アプリが持ち続ける state に古いコントローラとオーバーレイが残りません。destroy()で、ポリゴンと輪郭の manager を clear するようにしました(core のPolygonControllerと同じ)。別の PR との関係
#20(
refactor/polygon-controller)はMapboxPolygonConductorを削除して core のPolygonControllerに置き換えます。そちらが先にマージされた場合、この PR の conductor の変更は不要になります(core 側のdestroy()が同じことをします)。後にマージする側で衝突の手当てが要ります。関連 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 していません)を使っています。am dumpheap -gで GC させて、GC 後のヒープを測りました。MapLibreViewController/GoogleMapViewControllerが残り、それぞれ 98,843 件の PolygonEntity を抱えていました。testDebugUnitTestとapiCheckを流しました。新しく足したテストはすべて通っています。失敗は次の 5 つで、どれも develop の時点で同じ理由で落ちています。確認できていないもの: