地图的性能优化

优化点1:
如果是因为载入慢,那么我就让用户在载入这个过程中不要退出

优化点2:
在退出的时候,需要及时释放代理
viewwilldisappear的时候,delegate设置为nil

  • (void)viewWillDisappear:(BOOL)animated { [MAMapView shareMAMapView].showsUserLocation = NO; [MAMapView shareMAMapView].delegate = nil; [super viewWillDisappear:animated];}
    优化点3:关于内存的问题 ,因为我是每次进入地图的时候,都会new一个mapview出来,这样,如果进进出出,进进出出,CPU就跟火箭似的的,擦擦网上跑
    查了很多高德的社区论坛,和官方文档
    后来从高德某个回答的提醒下,想到用单例之前一直没用,是因为想到,地图本身不是一个高频的东西,没必要用单例而且是处于对高德地图的高度信任但是现在就结果来看,高德在内存方面做得并不好,而且代码存着各种问题
    最终决定用单例实现mapview具体代码如下:
    static MAMapView *_mapView = nil;+ (MAMapView *)shareMAMapView { @synchronized(self) { [MAMapServices sharedServices].apiKey = kAMapSearchApplicationSecretKey; if (_mapView == nil) { CGRect frame = [[UIScreen mainScreen] bounds]; _mapView = [[MAMapView alloc] initWithFrame:frame]; _mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; _mapView.showsUserLocation = YES; // _mapView.rotateEnabled = YES; // _mapView.rotateCameraEnabled = YES; _mapView.zoomEnabled = YES; } _mapView.frame = [UIScreen mainScreen].bounds; return _mapView; }}//重写allocWithZone保证分配内存alloc相同+ (id)allocWithZone:(NSZone *)zone { @synchronized(self) { if (_mapView == nil) { _mapView = [super allocWithZone:zone]; return _mapView; // assignment and return on first allocation } } return nil; // on subsequent allocation attempts return nil}//保证copy相同+ (id)copyWithZone:(NSZone *)zone { return _mapView;}

文/pingpong_龘(作者)原文链接:http://www.jianshu.com/p/ad3a51db3c64著作权归作者所有,转载请联系作者获得授权,并标注“作者”。

你可能感兴趣的:(地图的性能优化)