我目前正在使用,MKSnapshotter
但我注意到(类似于 MKMapView)它会占用大量内存,并且在应用程序运行期间从不释放它。我试过释放内存但没有用:
-(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];
}];