代码之家  ›  专栏  ›  技术社区  ›  Andiih

MKMapView是否存在漏洞

  •  1
  • Andiih  · 技术社区  · 16 年前

    还有我的问题“删除” MKMapView 注释导致泄漏。“我发现,如果创建基于视图的项目,请添加 UISearchBar 进入视图的NIB,连接委托(我不创建任何方法,因为我们实际上不需要做任何事情来触发泄漏),链接MapKit并启动项目,然后只需单击 搜索栏 导致1k+泄漏。除非你两者都有,否则这不会发生 搜索栏 MKMapView 从某种角度来看。在从代码创建视图时,我也遇到同样的问题。我认为笔尖的行为可能会有所不同,但事实并非如此。

    MKMapView 漏水,或者我做错了什么。

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

    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保留了子视图,但这可能不需要复制该问题。

    在发布此代码之前测试此代码时,我刚刚注意到此泄漏不会发生在模拟器中-仅发生在我的手机上。。。