Like my question "Removing MKMapView Annotations cause leaks." I found that if you create a project based on the view, add the UISearchBar and MKMapView to the NIB view, include the delegates (I do not create any methods, since we actually do not need to do anything to start the leak), the link in MapKit and the project start, and just a click in the UISearchBar causes a 1k + leak. This does not happen if you have both a UISearchBar and MKMapView in the view. I have the same problems when creating views from code. I thought the NIB might behave differently, but it is not.
Is MKMapView leaky or am I doing something wrong.
To replicate the problem with the code, try the code below - I created a new project based on a view based on
TestMapViewFromCodeViewController.h
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 retained the subviews with mapView and searchBar, this is probably not needed to replicate the problem.
When testing this code before publishing here, I just noticed that this leak does not occur in the simulator - only on my phone ...
memory-management objective-c iphone mapkit
Andiih
source share