From 1039f215273d8fb39d857bd6f82601f946d832c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Fri, 22 Apr 2016 12:53:19 -0700 Subject: [PATCH] [ios, osx] Fixed dangling KVO observer crash Fixed a crash when deallocating an MGLMapView that has point annotations. Now we explicitly remove all the annotations from the view and thus remove all remaining KVO observers on those annotations. Fixes #4805. --- platform/ios/src/MGLMapView.mm | 3 +++ platform/osx/src/MGLMapView.mm | 3 +++ 2 files changed, 6 insertions(+) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 9831c379a12..5ae2d79fc41 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -508,6 +508,9 @@ - (void)dealloc [[NSNotificationCenter defaultCenter] removeObserver:self]; [_attributionButton removeObserver:self forKeyPath:@"hidden"]; + // Removing the annotations unregisters any outstanding KVO observers. + [self removeAnnotations:self.annotations]; + [self validateDisplayLink]; if (_mbglMap) diff --git a/platform/osx/src/MGLMapView.mm b/platform/osx/src/MGLMapView.mm index 6ef93b70cf2..c707ef25719 100644 --- a/platform/osx/src/MGLMapView.mm +++ b/platform/osx/src/MGLMapView.mm @@ -450,6 +450,9 @@ - (void)dealloc { [self.calloutForSelectedAnnotation close]; self.calloutForSelectedAnnotation = nil; + // Removing the annotations unregisters any outstanding KVO observers. + [self removeAnnotations:self.annotations]; + if (_mbglMap) { delete _mbglMap; _mbglMap = nullptr;