ios – MKMapView没有为MKUserLocation释放内存

ios – MKMapView没有为MKUserLocation释放内存,第1张

概述我有一个导航控制器,其中VC1将VC2推送到导航堆栈. VC2在基于选项卡的视图中有一个MKMapView,用户位置已打开.当我使用Heapshot Analysis工具检查仪器的重复分配时,我重复发现当我回到VC1时,一些MKUserLocation对象没有被释放. 我删除了所有注释,并在dealloc时禁用了用户位置.这种堆增长的原因是什么? 将VC2推送到导航堆栈的VC1代码: - (NSI 我有一个导航控制器,其中VC1将VC2推送到导航堆栈. VC2在基于选项卡的视图中有一个MKMapVIEw,用户位置已打开.当我使用Heapshot Analysis工具检查仪器的重复分配时,我重复发现当我回到VC1时,一些MKUserLocation对象没有被释放.

我删除了所有注释,并在dealloc时禁用了用户位置.这种堆增长的原因是什么?

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

- (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 heapshotmapVIEw.delegate = nil;[mapVIEw release];mapVIEw = nil;[super dealloc];

}

此外,如果我不打开用户位置,则没有堆增长.

更新:我已经在模拟器和iPad 3G WiFi上对此进行了测试,我发现这两种情况下的堆增长.

解决方法 如果要在IB中创建MKMapVIEw,则应该在 -viewDidUnload AND -dealloc中释放/取消它.

如果不这样做,如果在视图控制器的生命周期内卸载/重新加载视图,则所有视图元素(无论如何都设置为保留属性)将在重新加载时泄漏.

在网络/ SO上似乎有相当数量的喋喋不休,说这是5.0.0之前的API错误.您要构建哪个版本的SDK?

此外,在黑暗中拍摄:只尝试

self.mapVIEw.showsUserLocation = NO;

要么

self.mapVIEw.showsUserLocation = NO;[self.mapVIEw.layer removeAllAnimations];[self.mapVIEw removeAnnotations:self.mapVIEw.annotations];

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

可能是你在MKMapVIEw有机会正确拆除它之前删除MKUserLocation的注释?

总结

以上是内存溢出为你收集整理的ios – MKMapView没有为MKUserLocation释放内存全部内容,希望文章能够帮你解决ios – MKMapView没有为MKUserLocation释放内存所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1052740.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存