views:

189

answers:

2

I have a MKMapView. Sometimes after my view controller is dismissed, I'll get a EXC_BAD_ACCESS.

I turned on NSSZombies and it looks like the MKMapView's delegate — my view controller! — is being called, despite both the MKMapView and UIViewController subclass being freed. I've checked, and my memory management is correct.

What's going on?

+2  A: 

It looks like this is a bug in MapKit. There's an operation pending, so MapKit is retaining the MKMapView and it hasn't actually been deallocated yet. That isn't itself a problem. The problem is that it's still sending messages to your delegate.

The workaround is simple: As part of your view controller's cleanup set the map view's delegate to nil, which will prevent MKMapView from sending messages to it.

Steven Fisher
A: 

I have the same issue with MKMapView leaking, and the solution noted here does not work. Setting the map view's delegate to nil does not prevent the leaking. Does anybody have a suggestion for another approach?