From 172c814d5357ffad0137526483dfac6bcce0eb08 Mon Sep 17 00:00:00 2001 From: Masashi Katsumata Date: Sat, 7 Nov 2026 13:16:50 -0800 Subject: [PATCH 1/2] Destroy the MapView when the map leaves the composition Nothing destroyed the MapView, so its render thread kept the old controller with every overlay. It is now destroyed through MapViewBase's onDestroyMapView (not stopped first: it was never started). --- src/main/java/com/mapconductor/mappls/MapplsMapView.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/mapconductor/mappls/MapplsMapView.kt b/src/main/java/com/mapconductor/mappls/MapplsMapView.kt index 862b41f..4bcc1c3 100644 --- a/src/main/java/com/mapconductor/mappls/MapplsMapView.kt +++ b/src/main/java/com/mapconductor/mappls/MapplsMapView.kt @@ -187,6 +187,11 @@ fun MapplsMapView( // For now, assuming content relates to overlay definitions. style = style, onStyleDiagnostics = onStyleDiagnostics, + // Never started (onStart is not called), so it is not stopped either -- + // MapView.onStop() would deactivate the shared FileSource the next map + // still uses. Destroying it ends the render thread, whose camera + // listeners otherwise keep the controller and every overlay alive. + onDestroyMapView = { mapView -> mapView.onDestroy() }, content = content, // This might need adjustment based on how overlays are handled ) } From f557259444a6b313b2cfea72787f354f2ef228a4 Mon Sep 17 00:00:00 2001 From: Masashi Katsumata Date: Sat, 7 Nov 2026 16:20:26 -0800 Subject: [PATCH 2/2] Read the controller through the state base, which MapViewBase clears 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. --- .../java/com/mapconductor/mappls/MapplsViewStateImpl.kt | 6 ++++-- .../mapconductor/mappls/polygon/MapplsPolygonConductor.kt | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/mapconductor/mappls/MapplsViewStateImpl.kt b/src/main/java/com/mapconductor/mappls/MapplsViewStateImpl.kt index 6e73d5b..64c1656 100644 --- a/src/main/java/com/mapconductor/mappls/MapplsViewStateImpl.kt +++ b/src/main/java/com/mapconductor/mappls/MapplsViewStateImpl.kt @@ -21,7 +21,10 @@ class MapplsViewState( cameraPosition: MapCameraPosition = MapCameraPosition.Default, ) : MapViewState(cameraPosition), MapplsViewStateInterface { - private var controller: MapplsViewControllerInterface? = null + // Read through the base so that letting go of the controller there (MapViewBase + // does it when the map is torn down) leaves nothing behind here. + private val controller: MapplsViewControllerInterface? + get() = attachedMapController as? MapplsViewControllerInterface private var _mapDesignType: MapplsMapDesignTypeInterface = mapDesignType override var mapDesignType: MapplsMapDesignTypeInterface @@ -32,7 +35,6 @@ class MapplsViewState( get() = _mapDesignType internal fun setController(controller: MapplsViewControllerInterface) { - this.controller = controller attachController(controller) } diff --git a/src/main/java/com/mapconductor/mappls/polygon/MapplsPolygonConductor.kt b/src/main/java/com/mapconductor/mappls/polygon/MapplsPolygonConductor.kt index 25bb1a9..18cd0df 100644 --- a/src/main/java/com/mapconductor/mappls/polygon/MapplsPolygonConductor.kt +++ b/src/main/java/com/mapconductor/mappls/polygon/MapplsPolygonConductor.kt @@ -130,7 +130,10 @@ class MapplsPolygonConductor( } override fun destroy() { - // No native resources to clean up for polygons + // A destroyed conductor can still be referenced (by its map controller, + // or a state that has not let go yet); without this it keeps every entity. + polygonOverlay.polygonManager.clear() + polylineOverlay.polylineManager.clear() } }