protected override void Dispose(bool disposing) { if (_disposed) { return; } _disposed = true; if (disposing) { if (Element != null) { var mapModel = (Map)Element; MessagingCenter.Unsubscribe <Map, MapSpan>(this, MoveMessageName); ((ObservableCollection <Pin>)mapModel.Pins).CollectionChanged -= OnPinCollectionChanged; ((ObservableCollection <MapElement>)mapModel.MapElements).CollectionChanged -= OnMapElementCollectionChanged; foreach (Pin pin in mapModel.Pins) { pin.PropertyChanged -= PinOnPropertyChanged; } } var mkMapView = (MKMapView)Control; mkMapView.DidSelectAnnotationView -= MkMapViewOnAnnotationViewSelected; mkMapView.RegionChanged -= MkMapViewOnRegionChanged; mkMapView.GetViewForAnnotation = null; mkMapView.OverlayRenderer = null; if (mkMapView.Delegate != null) { mkMapView.Delegate.Dispose(); mkMapView.Delegate = null; } mkMapView.RemoveFromSuperview(); #if __MOBILE__ mkMapView.RemoveGestureRecognizer(_mapClickedGestureRecognizer); _mapClickedGestureRecognizer.Dispose(); _mapClickedGestureRecognizer = null; if (FormsMaps.IsiOs9OrNewer) { // This renderer is done with the MKMapView; we can put it in the pool // for other rendererers to use in the future MapPool.Add(mkMapView); } #endif // For iOS versions < 9, the MKMapView will be disposed in ViewRenderer's Dispose method if (_locationManager != null) { _locationManager.Dispose(); _locationManager = null; } _lastTouchedView = null; } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (_disposed) { return; } _disposed = true; if (disposing) { if (Element != null) { var mapModel = (Map)Element; MessagingCenter.Unsubscribe <Map, MapSpan>(this, MoveMessageName); ((ObservableCollection <Pin>)mapModel.Pins).CollectionChanged -= OnCollectionChanged; } var mkMapView = (MKMapView)Control; mkMapView.RegionChanged -= MkMapViewOnRegionChanged; mkMapView.GetViewForAnnotation = null; mkMapView.Delegate.Dispose(); mkMapView.Delegate = null; mkMapView.RemoveFromSuperview(); #if __MOBILE__ if (FormsMaps.IsiOs9OrNewer) { // This renderer is done with the MKMapView; we can put it in the pool // for other rendererers to use in the future MapPool.Add(mkMapView); } #endif // For iOS versions < 9, the MKMapView will be disposed in ViewRenderer's Dispose method if (_locationManager != null) { _locationManager.Dispose(); _locationManager = null; } } base.Dispose(disposing); }