Swift Mapkit删除注释并释放内存



我正在使用mapView.removeAnnotations(mapView.annotations(来删除注释,但从Xcode中的调试中可以看到,每个注释的内存没有释放,这最终导致我的应用程序崩溃。有办法释放它吗?我已经看过ARC、去比特和弱,但我看不出这与我的代码有什么关系。

import Foundation
import MapKit
class StationMarkerView: MKMarkerAnnotationView {
override var annotation: MKAnnotation? {
willSet {

guard let station = newValue as? Station else {
return
}
canShowCallout = true
let mapsButton = FavouriteButton()
let  bool = station.is_favourite
let image = bool! ? "star.fill": "star"

mapsButton.setBackgroundImage(UIImage(systemName: image), for: .normal)

rightCalloutAccessoryView = mapsButton

markerTintColor = station.markerTintColor
glyphImage = station.glyphImage

}
}
}

我试过用weak表示";mapButton";但Xcode给了我一个解除定位的警告。

感谢任何帮助。

我找到了一个快速而肮脏的问题解决方案。删除注释然后更改映射类型似乎可以释放与mapView相关的所有内存。

所以为了刷新我的地图,我。。。

mapView.removeAnnotations(mapView.annotations)

mapView.mapType = MKMapType.satellite

velibManager.fetchVelib()

mapView.mapType = MKMapType.standard

最新更新