Memory leak with ABPeoplePickerNavigationControlle

2020-04-11 09:32发布

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:

memory leak in instruments

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.

2条回答
一夜七次
2楼-- · 2020-04-11 10:32

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

查看更多
相关推荐>>
3楼-- · 2020-04-11 10:39

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.

查看更多
登录 后发表回答