Skip to content

Commit

Permalink
Fix a memory leak with the tower markers and tower info windows
Browse files Browse the repository at this point in the history
  • Loading branch information
christianrowlands committed Jul 24, 2024
1 parent 80b0555 commit 57e0af8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,9 @@ private suspend fun runTowerQuery(viewModel: TowerMapViewModel) {
val towerMarker = TowerMarker(viewModel.mapView, it)

if (towers.size >= MAX_TOWERS_ON_MAP) {
towers.remove(towers.first())
val towerToRemove = towers.first()
towers.remove(towerToRemove)
towerToRemove.destroy()
}

if (towers.contains(towerMarker)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import com.craxiom.networksurvey.util.CellularUtils
import org.osmdroid.util.GeoPoint
import org.osmdroid.views.MapView
import org.osmdroid.views.overlay.Marker
import org.osmdroid.views.overlay.infowindow.MarkerInfoWindow

class TowerMarker(private val mapView: MapView, tower: Tower) : Marker(mapView) {
class TowerMarker(private val mapView: MapView, private val tower: Tower) : Marker(mapView) {
var cgiId: String

init {
Expand All @@ -23,14 +24,12 @@ class TowerMarker(private val mapView: MapView, tower: Tower) : Marker(mapView)
BlendModeColorFilterCompat.createBlendModeColorFilterCompat(
R.color.colorPrimary, BlendModeCompat.SRC_ATOP
)
setPosition(GeoPoint(tower.lat, tower.lon))
position = GeoPoint(tower.lat, tower.lon)
setAnchor(ANCHOR_CENTER, ANCHOR_BOTTOM)
icon = towerDrawable
title = getTitleString(tower)
cgiId = CellularUtils.getTowerId(tower)
setPanToView(false)

infoWindow = TowerMarkerInfoWindow(R.layout.bonuspack_bubble, mapView, this, tower)
}

override fun equals(other: Any?): Boolean {
Expand All @@ -51,6 +50,23 @@ class TowerMarker(private val mapView: MapView, tower: Tower) : Marker(mapView)
return result
}

override fun setInfoWindow(infoWindow: MarkerInfoWindow?) {
// Do nothing
}

override fun showInfoWindow() {
if (mInfoWindow == null) {
mInfoWindow = TowerMarkerInfoWindow(R.layout.bonuspack_bubble, mapView, this, tower)
}

super.showInfoWindow()
}

fun destroy() {
mapView.overlays.remove(this)
this.onDestroy()
}

fun setServingCell(isServingCell: Boolean) {
val towerDrawable =
AppCompatResources.getDrawable(
Expand Down

0 comments on commit 57e0af8

Please sign in to comment.