[英]iPhone ABPeoplePickerNavigationController Memory Leaks
I am going through my application killing off all the memory leaks and the analyze tool comes up with a leak using the abpeoplepickernavigationcontroller. 我正在通过我的应用程序消除所有内存泄漏,分析工具使用abpeoplepickernavigationcontroller发现泄漏。
I understand it is something to do with a copy method? 我明白这与复制方法有关吗? but don't know how to go about releasing it where and at the write time. 但不知道如何在写入时间和地点释放它。
I basically need to present the modal view, select the phonenumber then drag it back into the textfield. 我基本上需要提供模态视图,选择phonenumber然后将其拖回文本字段。 heres my code 继承我的代码
-(IBAction)openAddressBook{
ABPeoplePickerNavigationController *peoplepicker = [[ABPeoplePickerNavigationController alloc] init];
peoplepicker.peoplePickerDelegate = self;
[self presentModalViewController:peoplepicker animated:YES];
[peoplepicker 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
{
//Retrieving the phone number property of ABRecordRef
ABMultiValueRef phoneProperty = ABRecordCopyValue(person, property);
NSString *phone = (NSString *)ABMultiValueCopyValueAtIndex(phoneProperty, identifier);
phone = [phone stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSArray *brokenNumber = [phone componentsSeparatedByString:@" "];
phone = [brokenNumber componentsJoinedByString:@""];
if(![phonenumber.text isEqualToString:@""])
phonenumber.text = [NSString stringWithFormat:@"%@%@", phonenumber.text, @";"];
phonenumber.text = [NSString stringWithFormat:@"%@%@", phonenumber.text, phone];
[self dismissModalViewControllerAnimated:YES];
return NO;
}
Thanks 谢谢
The problem is likely to be here: 问题可能在这里:
ABMultiValueRef phoneProperty = ABRecordCopyValue(person, property);
NSString *phone = (NSString *)ABMultiValueCopyValueAtIndex(phoneProperty, identifier);
phone = [phone stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
You get objects copies with ABRecordCopyValue
and ABMultiValueCopyValueAtIndex
and they aren't released. 您可以使用ABRecordCopyValue
和ABMultiValueCopyValueAtIndex
获取对象副本 ,但不会释放它们。
ABMultiValueRef phoneProperty = ABRecordCopyValue(person, property);
NSString *phone = (NSString *)ABMultiValueCopyValueAtIndex(phoneProperty, identifier);
if (phoneProperty) {
CFRelease(phoneProperty);
}
NSString *trimmedPhone = [phone stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if (phone) {
CFRelease(phone);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.