diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index 9f0bc3af1..e654f1d72 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -102,6 +102,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT ### Networking and offline maps +* Fixed a leak of MGLReachability objects and threads in MGLMapView. ([#7956](https://github.com/mapbox/mapbox-gl-native/pull/7956)) * Fixed an issue preventing an MGLMapView from loading tiles while an offline pack is downloading. ([#6446](https://github.com/mapbox/mapbox-gl-native/pull/6446)) * Fixed a crash that could occur when the device is disconnected while downloading an offline pack. ([#6293](https://github.com/mapbox/mapbox-gl-native/pull/6293)) * Fixed a crash that occurred when encountering a rate-limit error in response to a network request. ([#6223](https://github.com/mapbox/mapbox-gl-native/pull/6223)) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 35ad58308..0c438d560 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -314,6 +314,8 @@ public: MGLCompassDirectionFormatter *_accessibilityCompassFormatter; NS_ARRAY_OF(MGLAttributionInfo *) *_attributionInfos; + + MGLReachability *_reachability; } #pragma mark - Setup & Teardown - @@ -440,12 +442,12 @@ public: name:kMGLReachabilityChangedNotification object:nil]; - MGLReachability* reachability = [MGLReachability reachabilityForInternetConnection]; - if ([reachability isReachable]) + _reachability = [MGLReachability reachabilityForInternetConnection]; + if ([_reachability isReachable]) { _isWaitingForRedundantReachableNotification = YES; } - [reachability startNotifier]; + [_reachability startNotifier]; // Set up annotation management and selection state. _annotationImagesByIdentifier = [NSMutableDictionary dictionary]; @@ -664,6 +666,8 @@ public: - (void)dealloc { + [_reachability stopNotifier]; + [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] removeObserver:self]; [_attributionButton removeObserver:self forKeyPath:@"hidden"]; diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md index 0e68a50e2..638b249cb 100644 --- a/platform/macos/CHANGELOG.md +++ b/platform/macos/CHANGELOG.md @@ -84,6 +84,7 @@ This version of the Mapbox macOS SDK corresponds to version 3.4.0 of the Mapbox ### Networking and offline maps +* Fixed a leak of MGLReachability objects and threads in MGLMapView. ([#7956](https://github.com/mapbox/mapbox-gl-native/pull/7956)) * Fixed an issue preventing an MGLMapView from loading tiles while an offline pack is downloading. ([#6446](https://github.com/mapbox/mapbox-gl-native/pull/6446)) * Fixed an issue causing an MGLOfflinePack’s progress to continue to update after calling `-suspend`. ([#6186](https://github.com/mapbox/mapbox-gl-native/pull/6186)) * Fixed an issue preventing cached annotation images from displaying while the device is offline. ([#6358](https://github.com/mapbox/mapbox-gl-native/pull/6358)) diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index 86d74d768..d687a19ae 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -193,6 +193,9 @@ public: /// True if the view is currently printing itself. BOOL _isPrinting; + + /// reachability instance + MGLReachability *_reachability; } #pragma mark Lifecycle @@ -273,11 +276,11 @@ public: self.layer = _isTargetingInterfaceBuilder ? [CALayer layer] : [MGLOpenGLLayer layer]; // Notify map object when network reachability status changes. - MGLReachability *reachability = [MGLReachability reachabilityForInternetConnection]; - reachability.reachableBlock = ^(MGLReachability *) { + _reachability = [MGLReachability reachabilityForInternetConnection]; + _reachability.reachableBlock = ^(MGLReachability *) { mbgl::NetworkStatus::Reachable(); }; - [reachability startNotifier]; + [_reachability startNotifier]; // Install ornaments and gesture recognizers. [self installZoomControls]; @@ -497,6 +500,10 @@ public: } - (void)dealloc { + + [_reachability stopNotifier]; + + [self.window removeObserver:self forKeyPath:@"contentLayoutRect"]; [self.window removeObserver:self forKeyPath:@"titlebarAppearsTransparent"];