Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Remove extraneous nil check from MGLOfflineRegionObserver - #4293

Merged
1ec5 merged 1 commit into
masterfrom
1ec5-offline-pack-assert-4287
Mar 14, 2016
Merged

1ec5 merged 1 commit into
masterfrom
1ec5-offline-pack-assert-4287

Conversation

@1ec5

@1ec5 1ec5 commented Mar 12, 2016

Copy link
Copy Markdown
Contributor

Due to ARC, MGLOfflinePack can be deallocated at any time following its initialization. -dealloc ensures that the offline region observer is unset, but that step is asynchronous; there is no guarantee that it completes before the first status change update. In fact, the pack is deallocated before the first status change update unless it is captured outside of the MGLOfflinePackAdditionCompletionHandler. The pack nil check is unnecessary because the subsequent code would be a no-op.

This is an alternative fix for #4287.

/cc @jfirebaugh @boundsj @bsudekum

@1ec5 1ec5 added iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS crash offline labels Mar 12, 2016
@1ec5 1ec5 self-assigned this Mar 12, 2016
@1ec5 1ec5 added this to the ios-v3.2.0 milestone Mar 12, 2016
@1ec5

1ec5 commented Mar 12, 2016

Copy link
Copy Markdown
Contributor Author

Given the call to mbgl::DefaultFileSource::setOfflineRegionObserver() inside -dealloc, there won’t be a memory leak because MBGLOfflineRegionObserver only holds a weak reference to MGLOfflinePack. However, @bsudekum was seeing that the pack pointer would sometimes be garbage rather than nil when encountering this race condition. This is surprising because pack is a weak pointer.

Due to ARC, MGLOfflinePack can be deallocated at any time following its initialization. -dealloc ensures that the offline region observer is unset, but that step is asynchronous; there is no guarantee that it completes before the first status change update. In fact, the pack is deallocated before the first status change update unless it is captured outside of the MGLOfflinePackAdditionCompletionHandler. The pack nil check is unnecessary because the subsequent code would be a no-op.
@1ec5
1ec5 force-pushed the 1ec5-offline-pack-assert-4287 branch from 8a77f81 to 7e4dce0 Compare March 14, 2016 18:24
@1ec5
1ec5 merged commit 7e4dce0 into master Mar 14, 2016
@1ec5 1ec5 removed the in progress label Mar 14, 2016
@1ec5
1ec5 deleted the 1ec5-offline-pack-assert-4287 branch March 14, 2016 18:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

crash iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS offline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant