Ios 清除MKSnapshotter内存
我目前正在使用MKSnapshotter,但我注意到与MKMapView类似,它会占用大量内存,并且在应用程序运行期间从不释放它。我已尝试释放内存,但没有用:Ios 清除MKSnapshotter内存,ios,memory,mkmapsnapshotter,Ios,Memory,Mkmapsnapshotter,我目前正在使用MKSnapshotter,但我注意到与MKMapView类似,它会占用大量内存,并且在应用程序运行期间从不释放它。我已尝试释放内存,但没有用: -(void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; [self releaseMKMapSnapshotMem]; } -(void)releaseMKMapSnapshotMem{ self.snapshotter=nil;/
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[self releaseMKMapSnapshotMem];
}
-(void)releaseMKMapSnapshotMem{
self.snapshotter=nil;//MKSnapShotter
self.options=nil;//MKSnapShotterOptions
}
非常感谢您的帮助
更新
包括更多细节
MKMapSnapshotOptions * snapOptions= [[MKMapSnapshotOptions alloc] init];
self.options=snapOptions;
CLLocation * salonLocation = [[CLLocation alloc] initWithLatitude:self.lat longitude:self.long];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location.coordinate, 300, 300);
self.options.region = region;
self.options.size = self.view.frame.size;
self.options.scale = [[UIScreen mainScreen] scale];
MKMapSnapshotter * mapSnapShot = [[MKMapSnapshotter alloc] initWithOptions:self.options];
self.snapshotter =mapSnapShot;
[self.snapshotter startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
if (error) {
NSLog(@"[Error] %@", error);
return;
}
UIImage *image = snapshot.image;
self.mapImage = image;
NSData *data = UIImagePNGRepresentation(image);
[self saveMapDataToCache:data WithKey:mapName];
}];
试试这个:
MKMapSnapshotOptions * snapOptions= [[MKMapSnapshotOptions alloc] init];
CLLocation * salonLocation = [[CLLocation alloc] initWithLatitude:self.lat longitude:self.long];
//location.coordinate or salonLocation.coordinate below????
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location.coordinate, 300, 300);
snapOptions.region = region;
snapOptions.size = self.view.frame.size;
snapOptions.scale = [[UIScreen mainScreen] scale];
MKMapSnapshotter * mapSnapShot = [[MKMapSnapshotter alloc] initWithOptions: snapOptions];
[mapSnapShot startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
if (error) {
NSLog(@"[Error] %@", error);
return;
}
UIImage *image = snapshot.image;
NSData *data = UIImagePNGRepresentation(image);
[self saveMapDataToCache:data WithKey:mapName];
}];
我做的和你做的差不多,只有两个不同点:
options.region = _mapView.region;
options.size = _mapView.frame.size;
my _mapView是视图控制器中显示的地图…您的mapView属性声明是什么样子的?弱/强?可能需要一个弱小的…@meierjo它的弱小已经很小了更多信息?i、 e.向ViewCOntroller显示地图视图,用户保存位置,应用程序拍摄快照,保存快照,然后解除ViewCOntroller-等等。@meierjo ViewCOntroller显示,纬度和经度在MKSnapShotter中传递以拍摄图像,然后图像被缓存。@meierjo如需了解更多详细信息,请参阅上文。不显示地图,如果有意义的话,我只显示快照。你启动了跟踪堆增长的仪器了吗?谷歌/搜索这么多关于乐器的优秀图坦卡门