Is MKMapView leaky

对着背影说爱祢 提交于 2019-11-30 20:54:23

问题


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


回答1:


Yes.

There is a known leaks on 3.0's MKMapViews. The leak occurs when you deallocate the MKMapView This is fixed in later releases. The workaround is to have a single MKMapView and reuse it.

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




回答2:


For what its worth, there are similar related questions here:

  • https://stackoverflow.com/questions/5935243/mkmapview-rame-et-fuite-memoire-apple
  • Can the memory used by MKMapView be released some how?
  • MKMapView Memory Leak in iPhone Application


来源:https://stackoverflow.com/questions/1373421/is-mkmapview-leaky

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!