我有一个导航控制器,其中VC1将VC2推到导航堆栈上。VC2在基于选项卡的视图中有一个MKMapView,用户位置被打开。当我使用检查是否使用工具进行重复分配时,我反复发现一些MKUserLocation对象在返回VC1时没有被释放。

我已经删除了所有注释,并在dealloc上禁用了用户位置。堆增长的原因是什么?
将VC1推到导航堆栈上的VC2代码:
- (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;
}VC2中的dealloc代码:
- (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上测试了这一点,并且在这两种情况下都发现了堆的增长。
发布于 2012-01-17 09:22:13
如果要在IB中创建MKMapView,则应该在-viewDidUnload和-dealloc中发布/nil-ing。
如果没有,如果视图在视图控制器的生存期内被卸载/重新加载,则所有视图元素(无论如何都设置为保留属性)将在重新加载时泄漏。
网络上似乎有大量的聊天/所以说这是一个API的缺陷,前5.0.1。您是针对什么版本的SDK构建的?
另外,在黑暗中拍摄:只试一试
self.mapView.showsUserLocation = NO;或
self.mapView.showsUserLocation = NO;
[self.mapView.layer removeAllAnimations];
[self.mapView removeAnnotations:self.mapView.annotations];而不是现在使用的这些命令的顺序。
可能是在MKUserLocation有机会正确删除它之前,您正在删除MKMapView的注释吗?
https://stackoverflow.com/questions/8746549
复制相似问题