MKMapView是否漏洞 [英] Is MKMapView leaky

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

问题描述

除了我的问题删除 MKMapView 注释会导致泄漏。我发现如果你创建一个基于视图的项目,在视图的NIB中添加一个 UISearchBar MKMapView ,连接起来代理人(我没有创建任何方法,因为我们实际上不需要做任何事情来触发泄漏),在MapKit中链接并启动项目,然后只需单击 UISearchBar 导致1k +泄漏。除非您在视图中同时具有 UISearchBar MKMapView ,否则不会发生这种情况。从代码创建视图时我遇到了同样的问题。我认为NIB可能表现不同,但事实并非如此。

As well as my question "Removing MKMapView Annotations causes leaks." I have discovered that if you create a view based project, add a UISearchBar and MKMapView into the view's NIB, wire up the delegates (I'm not creating any methods as we don't actually need to do anything to trigger the leaks), link in the MapKit and fire up the project, then simply clicking in the UISearchBar causes a 1k+ leak. This doesn't happen unless you have both UISearchBar and MKMapView in a view. I have the same issues when creating the views from code. I thought a NIB might behave differently, but it doesn't.

MKMapView 是否泄漏,或者我在做什么有问题。

Is MKMapView leaky, or am I doing something wrong.

要使用代码复制问题,请尝试下面的代码 - 我创建了一个新的基于视图的应用程序项目

To replicate the issue with code try the code below - I created a new "view based application" project

TestMapViewFromCodeViewController.h

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>

@interface TestMapViewFromCodeViewController : UIViewController {
    UISearchBar *searchBar;
    MKMapView *mapView;

}

@property (nonatomic, retain) MKMapView *mapView;
@property (nonatomic, retain) UISearchBar *searchBar;


@end

TestMapViewFromCodeViewController.m

- (void)viewDidLoad {
    [super viewDidLoad];
    UISearchBar * tmpSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0,0.0,self.view.frame.size.width,40.0)];
    [self.view addSubview:tmpSearchBar];
    [self setSearchBar:tmpSearchBar];
    [tmpSearchBar release];

    MKMapView *tmpMapView=[[MKMapView alloc] initWithFrame:CGRectMake(0.0,0.0,self.view.frame.size.width,self.view.frame.size.height)];
    tmpMapView.showsUserLocation=FALSE;
    [self.view insertSubview:tmpMapView atIndex:0];
    [self setMapView:tmpMapView];
    [tmpMapView release];
}


- (void)dealloc {
    [mapView release];
    [searchBar release];
    [super dealloc];
}

虽然我使用mapView和searchBar保留了子视图,但这可能是不必要的复制问题。

Although I've retained the subviews with mapView and searchBar, this is probably unnecessary to replicate the issue.

在发布此处之前测试此代码我刚刚注意到模拟器中没有发生此泄漏 - 仅在我的手机上...

In testing this code prior to publishing here I've just noticed that this leak does not occur in the simulator - only on my phone...

推荐答案

是。

3.0上有一个已知的漏洞的MKMapViews。解除分配MKMapView时会发生泄漏。这在以后的版本中已得到修复。解决方法是使用单个MKMapView并重复使用它。

There is a known leaks on 3.0's MKMapViews. The leak occurs when you deallocate the MKMapView This is fixed in later releases. The workaround is to have a single MKMapView and reuse it.

https://devforums.apple .com / message / 129740#129740

这篇关于MKMapView是否漏洞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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