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.
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]; }
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...