问题
I'm using this code to display the contacts in an app.
- (IBAction) selectContact:(id)sender {
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
NSArray *displayedItems = [NSArray arrayWithObjects:[NSNumber numberWithInt:kABPersonAddressProperty], nil];
picker.displayedProperties = displayedItems;
[self presentModalViewController:picker animated:YES];
[picker release];
}
and there is a memory leak, according to instruments. Even if I cancel the person picker like this:
- (void) peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker {
NSLog(@"peoplePickerNavigationControllerDidCancel");
[self dismissModalViewControllerAnimated:YES];
}
... I got a leak:
I have found some posts of developers claiming that this is a bug in the SDK and that a bug has already been filed. Can someone confirm that? or point me in the right direction.
回答1:
I know this goes against logic, and against everything you know, but please trust me on this. Comment out the line that releases the picker;
//-- [picker release]; this line must be commented
It's most likely a bug in the Apple SDK
回答2:
Try updating your SDK to the most recent iOS version, and see if the leak still occurs. If it does, please file a bug through the developer center.
来源:https://stackoverflow.com/questions/5074684/memory-leak-with-abpeoplepickernavigationcontroller