我有一个导航控制器,其中VC1将VC2压入导航堆栈。 VC2在基于标签的视图中有一个MKMapView,用户位置打开。当我使用Heapshot Analysis工具检查仪器重复分配时,当我回到VC1时,我反复查找一些MKUserLocation对象没有被释放。 MKMapView并没有为MKUserLocation释放内存
我已经删除了所有注释,并在dealloc时禁用了用户位置。这可能是堆增长的原因?
- (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代码在VC2:
是推动VC2到导航堆栈VC1代码
- (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];
}
此外,不存在堆的增长,如果我不打开用户位置。
更新:我已经在模拟器和iPad 3G + WiFi上测试了这一点,我发现这两种情况下堆增长。
VC2中的dealloc真的被调用了吗? – Anna 2012-01-05 17:29:02
是的,所有其他对象都被释放。我通过取出另一个对象的dealloc来检查它,并且它开始出现在heapshot中。 – 2012-01-05 17:54:17
你可以发布VC2 dealloc方法和创建VC2的VC1中的代码并推送它吗?您是否尝试过关闭用户位置,并将地图的代理设置为无VC2的viewWillDisappear? – Anna 2012-01-05 18:08:07