DEPRECATED-mapbox-ios-sdk icon indicating copy to clipboard operation
DEPRECATED-mapbox-ios-sdk copied to clipboard

Possible problems with _mapScrollView.delegate

Open chchrn opened this issue 10 years ago • 1 comments

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.

chchrn avatar May 20 '15 07:05 chchrn

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;
    }
    // !!!
}

vzqwer avatar Aug 13 '15 07:08 vzqwer