App crash with "Debugging Terminated"
I have CLLocation variable declared i gave it a value but when i use it at other place, app crash with "Debugging Terminated" without any logs in console
CLLocation *userLoc;
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
userLoc=newLocation;
[self somefunction];
}
-(void) somefunction
{
NSLog(@"%@",userLoc);
}
here it log userLoc properly
but in my other method
- (void) tableView:(UITableView *)tableView didSel开发者_JAVA百科ectRowAtIndexPath:(NSIndexPath*) indexPath
{
NSLog(@"%@",userLoc);
}
here app crash. Please help
Core Location provides you with autoreleased CLLocation object in delegates method, so it becomes invalid outside that method. To preserve it you need to retain location value:
userLoc=[newLocation retain];
Or, better, declare a property for your userLoc variable with retain attribute and use it the following way:
self.userLoc = newLocation;
P.S. Memory management guide is really a must-read...
精彩评论