在这一点上,我不确定这些泄漏是否与 CoreData 相关或什么,因为我在同一个应用程序的其他部分经历了 48 字节的 strdup 泄漏,原因显然不同 - 请参阅我的另一个问题:另一个堆栈溢出问题
但是,假设没有关系,我有一个 viewController,它基于用户选择一个选项,呈现一个 ABPeoplePicker。但是,无论是否选择联系人,似乎只是通过展示我正在泄漏的选择器。
呈现选择器的代码是:
- (void)showPeoplePickerController
{
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.displayedProperties = [NSArray arrayWithObject:[NSNumber numberWithInt:kABPersonEmailProperty]];
picker.peoplePickerDelegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];
}
委托方法实现如下:
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
{
[self dismissModalViewControllerAnimated:YES];
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
return YES;
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier
{
ABMultiValueRef emails = ABRecordCopyValue(person, property);
if(userEmailString)
[userEmailString release];
userEmailString = (NSString*)ABMultiValueCopyValueAtIndex(emails, identifier);
CFRelease(emails);
[[NSNotificationCenter defaultCenter] postNotificationName:@"recipientEmailDidUpdateNotification"
object:self];
return NO;
}
以防万一,userEmailString 是控制器的保留 NSString 属性(这意味着我也可以选择 self.userEmailString = blah)。
这些是 Instruments 的屏幕截图,报告了泄漏。但是请注意,它认为它的选择器没有被释放,尽管我在展示它之后调用了释放。而且我也尝试过做 CFRelease() ......但还是一样。