Is MKMapView faulty

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

 #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 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 ...

+1
memory-management objective-c iphone mapkit
source share
2 answers

Yes.

Leaks in 3.0 MKMapViews are known. A leak occurs when you release MKMapView. This is fixed in subsequent releases. The workaround is to have one MKMapView and reuse it.

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

+2
source share

For what it is, there are similar questions:

  • https://stackoverflow.com/questions/5935243/mkmapview-rame-et-fuite-memoire-apple
  • Is it possible to free the memory used by MKMapView, how?
  • MKMapView memory leak in iPhone application
0
source share

All Articles