以及我的问题“删除MKMapView
注释会导致泄漏。”我发现,如果您创建基于视图的项目,请添加UISearchBar
and MKMapView
进入视图的 NIB,连接委托(我没有创建任何方法,因为我们实际上不需要做任何事情来触发泄漏),链接到 MapKit 并启动项目,然后只需单击UISearchBar
导致 1k+ 泄漏。除非你两者都具备,否则这种情况不会发生UISearchBar
and MKMapView
在一个视图中。从代码创建视图时我遇到了同样的问题。我认为 NIB 的行为可能会有所不同,但事实并非如此。
Is 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 的子视图,但这可能没有必要复制该问题。
在在此发布之前测试此代码时,我刚刚注意到这种泄漏不会发生在模拟器中 - 仅发生在我的手机上......