I have a navigation controller in which VC1 pushes VC2 into the navigation stack. VC2 has MKMapView in a tab-based view with the user's location enabled. When I check re-selection with tools using the Heapshot Analysis tool, I repeatedly find that some MKUserLocation objects are not freed when I return to VC1. 
I deleted all annotations and also disabled the user's location on dealloc. What could be causing the heap to grow?
The VC1 code that pushes VC2 onto the navigation stack:
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath { VC2 *vc2 = [[VC2 alloc] init]; vc2.index = indexPath.row; [[NSNotificationCenter defaultCenter] removeObserver:self]; [[self navigationController] pushViewController:vc2 animated:YES]; [vc2 release]; vc2 = nil; return nil; }
Dealloc code in VC2:
- (void)dealloc { //Other UILabel, UITextField objects dealloc methods go here //The next four lines of code do not make a difference even if they are in viewWillDisappear [self.mapView removeAnnotations:self.mapView.annotations]; [self.mapView.layer removeAllAnimations]; self.mapView.showsUserLocation = NO;//This line does not make a difference in heapshot mapView.delegate = nil; [mapView release]; mapView = nil; [super dealloc];
}
Also, there is no heap growth unless I include the user's location.
Update: I tested this on a simulator and on an iPad 3G + WiFi, and I find this heap growth in both cases.
source share