Search code examples
mkmapviewmapkitnszombie

CLLocationManager onClientEventLocation, Zombie


The problem appears when I pressed MKUserTrackingBarButtonItem for tracking user location and then leave the view.

Profiler shows zombie:

[CLLocationManager onClientEventLocation]

I have no CLLocationManager but MKMapView, which I set to nil when exit:

    - (void)viewDidUnload
{
    [self setMapToolbar:nil];
    mapView.delegate = nil;
    [self setMapView:nil];

    [super viewDidUnload];
}

Solution

  • As I finally understand MKMapView showUserLocation method creates an instance of CLLocationManager.

    Easily avoid this zombie by turning userLocation off when quit view:

         - (void)viewWillDisappear:(BOOL)animated 
    { 
    [mapView setShowsUserLocation:NO]; 
    [super viewWillDisappear:animated]; 
    }