阻止iOS 7 MKMapView泄漏内存 [英] Stop iOS 7 MKMapView from leaking memory

查看:136
本文介绍了阻止iOS 7 MKMapView泄漏内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到我的应用程序泄漏了内存,但如果我拿出 MKMapView ,内存问题就会消失。

I've noticed that my app leaks memory, but if I take the MKMapView out the memory problem goes away.

为了测试这个理论,我创建了一个简单的项目,它有一个视图,用 MKMapView 推送视图在它和弹出和推动。而已。视图控制器中没有代码,通过故事板完成。

To test the theory, I made a dead simple project that has a view that pushes a view with a MKMapView in it and pops and pushes. Nothing more. No code in the view controllers, everthing done via storyboard.

如果我来回地图视图,在推送和弹出视图后,它开始大约3MB它中的地图约15倍,内存约为230MB。

If I go back and forth to the map view, it starts about 3MB after doing pushing and popping the view with the map in it this about 15 times the memory is around 230MB.

其他人看过这个?看起来像一个非常大的bug。有没有不同的方法来使用 MKMapView 来防止它泄漏这么多?

Anyone else seen this? Seems like a pretty big bug. Is there a different way to use MKMapView that will prevent it from leaking so much?

推荐答案

我遇到了同样的问题,并且(感谢Stackoverflow)通过在 viewWillDisappear 中更改 MKMapType 并解除分配/设置它来修复它委托给nil。因为它仍然向代表发送消息。
这在MKMapViewDelegate协议参考中有记录:

I had faced the same issue and (thanks to Stackoverflow) fixed it by changing MKMapType in viewWillDisappear and deallocating/setting its delegate to nil.As it still sends message to delegates. This is documented in MKMapViewDelegate Protocol Reference:


在发布已为其设置
委托的MKMapView对象之前,记得将该对象的委托属性设置为nil。一个
的地方你可以在dealloc方法中处理
地图视图

Before releasing an MKMapView object for which you have set a delegate, remember to set that object’s delegate property to nil. One place you can do this is in the dealloc method where you dispose of the map view

-(void)viewWillDisappear:(BOOL)animated{
  [super viewWillDisappear:animated];
  [self applyMapViewMemoryFix];

}

- (void)applyMapViewMemoryFix{

switch (self.mkMapView.mapType) {
    case MKMapTypeHybrid:
    {
        self.mkMapView.mapType = MKMapTypeStandard;
    }

        break;
    case MKMapTypeStandard:
    {
        self.mkMapView.mapType = MKMapTypeHybrid;
    }

        break;
    default:
        break;
}
self.mkMapView.showsUserLocation = NO;
self.mkMapView.delegate = nil;
[self.mkMapView removeFromSuperview];
self.mkMapView = nil;
}

希望这会有所帮助

这篇关于阻止iOS 7 MKMapView泄漏内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆