mapbox / DEPRECATED-mapbox-ios-sdk

REPLACED – use https://www.mapbox.com/ios-sdk instead
https://github.com/mapbox/mapbox-gl-native
Other
323 stars 8 forks source link

Possible problems with _mapScrollView.delegate #634

Open chchrn opened 9 years ago

chchrn commented 9 years ago

I think this is not safety:

- (void)createMapView
{
...
    _mapScrollView = [[RMMapScrollView alloc] initWithFrame:self.bounds];
    _mapScrollView.delegate = self;
...
}

- (void)dealloc
{
    [_moveDelegateQueue cancelAllOperations];
    [_zoomDelegateQueue cancelAllOperations];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [_mapScrollView removeObserver:self forKeyPath:@"contentOffset"];
    [_tileSourcesContainer cancelAllDownloads];
    _locationManager.delegate = nil;
    [_locationManager stopUpdatingLocation];
    [_locationManager stopUpdatingHeading];
}

Property "delegate" of UIScrollView is assign, not weak. In dealloc method your didn't set _mapScrollView.delegate to nil. This is a possible problem, because instance of UIScrollView can send a message to dealloced object.

vzqwer commented 9 years ago

I have a bug with this issue.

I have a class with

@property (nonatomic, weak) IBOutlet RMMapView *mapView;

Possible workaround I've found:

- (void)dealloc
{
    [self removeObservers];

    self.mapView.delegate = nil;

    // !!!: Workaround for https://github.com/mapbox/mapbox-ios-sdk/issues/634 !!!
    RMMapScrollView *mapScrollViewPrivate = [self.mapView valueForKey:@"_mapScrollView"];
    if (mapScrollViewPrivate)
    {
        mapScrollViewPrivate.delegate = nil;
    }
    // !!!
}