【发布时间】:2011-04-09 08:40:30
【问题描述】:
我从这个论坛知道这是一个已向 Apple 报告的已知错误,但我担心每次调用视图时内存泄漏都会不断增加。
相关代码是
-(IBAction)getlocationgo:(id) sender{
//NSAutoreleasePool *pool;
//pool = [[NSAutoreleasePool alloc] init];
self.locationManager=[[[CLLocationManager alloc]init]autorelease];
self.locationManager.delegate = self;
[locationManager startUpdatingLocation];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
//mapView.showsUserLocation =YES;
//[pool release];
}
- (void)locationManager:(CLLocationManager*)aManager didFailWithError:(NSError*)anError
{
switch([anError code])
{
case kCLErrorLocationUnknown: // location is currently unknown, but CL will keep trying
break;
case kCLErrorDenied: // CL access has been denied (eg, user declined location use)
{UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Location Error"
message:@"Please enable Location Services in the Settings menu"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
[alert show];
[alert release];}
break;
case kCLErrorNetwork: // general, network-related error
{UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Location Error"
message:@"The Little Helper can't find you - please check your network connection or that you are not in airplane mode"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
[alert show];
[alert release];}
break;
}
}
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
NSLog(@"thisruns");
MKCoordinateSpan span;
span.latitudeDelta =0.2;
span.longitudeDelta =0.2;
MKCoordinateRegion region;
region.span = span;
region.center = newLocation.coordinate;
[mapView setRegion:region animated:YES];
mapView.showsUserLocation =YES;
mapView.mapType = MKMapTypeHybrid;
latitude.text = [NSString stringWithFormat:@"%f",newLocation.coordinate.latitude];
longitude.text = [NSString stringWithFormat:@"%f",newLocation.coordinate.longitude];
NSString *newloc=longitude.text;
NSLog(@"long%f", newloc);
[locationManager stopUpdatingLocation];
}
该属性与此相关
@property (nonatomic, retain) CLLocationManager *locationManager;
它被释放了
mapView.delegate = nil;
[mapView release];
locationManager.delegate = nil;
[locationManager release];
这几天我一直在反复讨论这个问题,任何帮助或提示都会很棒。 谢谢
编辑一个 尝试在应用程序委托中访问 locationManager,一切都运行但没有从 IBaction 更新位置 这是 IBaction 中的代码,日志的结果是 (null)
LLHelperAppDelegate *appDelegate = (LLHelperAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.locationManager startUpdatingLocation];
appDelegate.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
NSLog(@"%@", [appDelegate locationManager]);
【问题讨论】:
标签: iphone memory-leaks mkmapview instruments core-location