我最近遇到了一个问题,我的 MapView 似乎使用了比它应该使用的更多的内存。我已经禁用了所有填充注释和下载数据等的方法,并且基本上只将应用程序留在地图视图中。地图视图在一个名为 Map Manager 的单例对象中进行初始化和分配,我通过地图使用该对象,因为我在多个视图中使用地图。所有地图处理方法也驻留在此对象中。运行我的应用程序时,缩放、划船、平移等非常不稳定且缓慢。我正在运行最新的 iPad Mini。
在 iOS7 上运行应用程序时,在 xCode 中,内存利用率报告峰值约为 180MB 内存。如果我运行该应用程序,然后同时打开 Apple Maps 并使用它,我会导致我的应用程序由于以下错误而崩溃:由于内存压力而终止。
下面是我在运行分配测试时的地图初始化程序和仪器配置文件:
+ (id)sharedInstance
{
static LBMapManager *mapManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// Intialize the class
mapManager = [[self alloc] init];
// Intialize map
mapManager.mapView = [[MKMapView alloc] init];
mapManager.mapView.mapType = [[LBSettings getObjectForKey:kLBSettingsMapType] intValue];
mapManager.mapView.showsBuildings = YES;
mapManager.mapView.showsPointsOfInterest = YES;
mapManager.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
});
return mapManager;
}
照片: