Swift Mapkit删除注释并释放内存

问题描述

我正在使用mapView.removeAnnotations(mapView.annotations)删除注释,但是从Xcode的调试中可以看到,每个注释的内存都没有释放,这最终导致我的应用崩溃。有没有办法释放它?我已经看过ARC以及deinit和weak,但是我看不到它与我的代码有什么关系。

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

我曾尝试对“ mapButton”使用弱函数,但Xcode给了我一个解除分配警告。

感谢任何帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)