MKMapView still sending messages to delegate after it's superview has been de-alloc'ed

前端 未结 2 1983
臣服心动
臣服心动 2021-02-19 07:52

EDIT: changed the title. I didn\'t know it at the time but this is a duplicate of Why am I crashing after MKMapView is freed if I'm no longer using it?


This q

2条回答
  •  旧时难觅i
    2021-02-19 08:26

    MKMapView is not compiled with ARC and because of that the property for delegate is still declared as assign instead of weak.
    From the MKMapView documentation:

    @property(nonatomic, assign) id delegate
    

    And from the Transitioning to ARC Release Notes:

    You may implement a dealloc method if you need to manage resources other than releasing instance variables. You do not have to (indeed you cannot) release instance variables, but you may need to invoke [systemClassInstance setDelegate:nil] on system classes and other code that isn’t compiled using ARC.


    For delegates of system classes (NS*, UI*) you have to use the "old" rule of setting delegates to nil when you deallocate the delegate object.

    so add a dealloc method to your detailViewController

    - (void)dealloc {
        self.mapView.delegate = nil;
    }
    

提交回复
热议问题