Clear location service object in resign active

Since iOS 4.0, I am aware freeing unnecessary object when the application is in inactive state so that the app can free up as much memory as possible. So in one of me location based app, I try to free the location service object when it is inactive:


- (void)applicationWillResignActive:(UIApplication *)application {
self.locationService = nil;
....
/*
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
*/
}

It is a big mistake! When you called the [self.locationService startUpdatingLocation], in the first several trial, the system will prompt user for allowing the location service for this app. When the dialog is popup, the application is actually switched to inactive state, and applicationWillResignActive will be called. If you free the location service object, the dialog will be closed immediately and the process will failed.