首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MKMapView没有释放MKUserLocation的内存

MKMapView没有释放MKUserLocation的内存
EN

Stack Overflow用户
提问于 2012-01-05 17:04:57
回答 1查看 2.2K关注 0票数 4

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

我已经删除了所有注释,并在dealloc上禁用了用户位置。堆增长的原因是什么?

将VC1推到导航堆栈上的VC2代码:

代码语言:javascript
复制
- (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代码:

代码语言:javascript
复制
- (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上测试了这一点,并且在这两种情况下都发现了堆的增长。

EN

回答 1

Stack Overflow用户

发布于 2012-01-17 09:22:13

如果要在IB中创建MKMapView,则应该在-viewDidUnload-dealloc中发布/nil-ing。

如果没有,如果视图在视图控制器的生存期内被卸载/重新加载,则所有视图元素(无论如何都设置为保留属性)将在重新加载时泄漏。

网络上似乎有大量的聊天/所以说这是一个API的缺陷,前5.0.1。您是针对什么版本的SDK构建的?

另外,在黑暗中拍摄:只试一试

代码语言:javascript
复制
self.mapView.showsUserLocation = NO;

代码语言:javascript
复制
self.mapView.showsUserLocation = NO;
[self.mapView.layer removeAllAnimations];
[self.mapView removeAnnotations:self.mapView.annotations];

而不是现在使用的这些命令的顺序。

可能是在MKUserLocation有机会正确删除它之前,您正在删除MKMapView的注释吗?

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8746549

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档