Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6958909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:12:06+00:00 2026-05-27T15:12:06+00:00

EDIT: changed the title. I didn’t know it at the time but this is

  • 0

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 question is similar to Why is object not dealloc'ed when using ARC + NSZombieEnabled but different enough that I thought it worth throwing out there in case anyone understands and can explain to me what is happening. The other question may be an XCode bug so I presume this could be similar.

Scenario:

  1. RootViewController has a tableView displaying a bunch of items
  2. Selecting a cell presents a modal detailViewController containing another tableView
  3. One of the table cells in detailViewController contains an MKMapView showing the location of the item
  4. mapView.delegate = detailViewController
  5. Dismiss the modal detailViewController

Soon after this, the app crashes b/c the MKMapView sends mapView:viewForAnnotation: to the now dealloc’ed detailViewController. This crash repro’ed on a users device with an ad-hoc distribution build so the issue has nothing to do with NSZombieEnabled.

I was able to resolve the crash by adding:

_mapView.delegate = nil;

to the dealloc method of the tableViewCell containing the mapView.

QUESTION: why is it necessary to nil the delegate when the cell is dealloc’ed? It seems like the mapView should be dealloc’ed by ARC when the cell is dealloc’ed leaving this unnecessary. It is good practice to nil delegates but I didn’t think it would be required in this case.

EDIT: all subviews of both detailViewController and the UITableViewCells are declared as (nonatomic, strong) properties ala:

@property (nonatomic, strong)   MKMapView *         mapView;

EDIT 2: Guess I need to get better at reading the docs. @fluchtpunkt is correct. Here’s the relevant info from the MKMapView documentation:

Before releasing an MKMapView object for which you have set a
delegate, remember to set that object’s delegate property to nil. One
place you can do this is in the dealloc method where you dispose of
the map view.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:12:07+00:00Added an answer on May 27, 2026 at 3:12 pm

    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<MKMapViewDelegate> 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;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: This question title originally was: How does Doctrine know last inserted id in
EDIT: changed the title to fit the code below. I'm trying to retrieve a
Edit: Changed question title from Does C# allow method overloading, PHP style (__call)? -
Note: The title of this was changed to better reflect the actual problem. I've
EDIT : Changed title from inheritance to composition. Left body of question unchanged. I'm
EDIT:I've changed the title, because the issue had nothing to do with IE image.load()
EDIT: Changed title to actually be correct I'm trying to simulate a modal popup
[EDIT] This question is how do I do atomic changes to entity beans with
Edit: This question was written in 2008, which was like 3 internet ages ago.
EDIT: This was formerly more explicitly titled: - Best solution to stop Kontiki's KHOST.EXE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.