Mapbox in Jetpack Compose takes up a lot of RAM. When I open the view that contains the map, the memory takes more and more each time I go into that view.
How can I destroy the memory When I left the view?
AndroidView(modifier = Modifier.height(240.dp).clip(RoundedCornerShape(topStart = 10.dp, topEnd = 10.dp)),
factory = {
View.inflate(it, R.layout.main_mapview_mapbox, null)
MapView(it).apply {
mapView = this
getMapboxMap().loadStyleUri("mapbox://styles/.../....") {sty ->
trip.listOfLatLon.let { points ->
val polygon = Polygon.fromLngLats(listOf(points))
val cameraPosition = getMapboxMap().cameraForGeometry(polygon,padding =
EdgeInsets(220.0, 320.0, 220.0, 320.0))
val viewAnnotationManager = this.viewAnnotationManager
viewAnnotationManager.addViewAnnotation(
R.layout.camera_report_annotation,
viewAnnotationOptions {
geometry(points[0])
allowOverlap(false)
anchor(ViewAnnotationAnchor.BOTTOM)
visible(true)
}
)
viewAnnotationManager.addViewAnnotation(
R.layout.police_report_annotation,
viewAnnotationOptions {
geometry(points[trip.listOfLatLon.size - 1])
allowOverlap(false)
anchor(ViewAnnotationAnchor.CENTER)
visible(true)
}
)
getMapboxMap().setCamera(cameraPosition)
}
var data = geoJsonSource("line") {
featureCollection(FeatureCollection.fromFeature(feature))
}
sty.addSource(data)
sty.addLayer(lineLayer("linelayer", "line") {
lineCap(LineCap.ROUND)
lineJoin(LineJoin.ROUND)
lineWidth(4.0)
lineColor("#495CE8")
})
}
scalebar.enabled = false
compass.enabled = false
gestures.scrollEnabled = false
gestures.pitchEnabled = false
}
})
}