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 ) } 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() } }