iPhone ABPeoplePickerNavigationController 内存泄漏
我正在检查我的应用程序,消除所有内存泄漏,分析工具使用 abpeoplepickernavigationcontroller 发现泄漏。
我理解这与复制方法有关?但不知道如何在写入时在何处释放它。
我基本上需要呈现模式视图,选择电话号码,然后将其拖回文本字段。这是我的代码
-(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;
}
谢谢
I am going through my application killing off all the memory leaks and the analyze tool comes up with a leak using the 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. 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题可能出在这里:
您使用
ABRecordCopyValue
和ABMultiValueCopyValueAtIndex
获取对象副本,但它们没有被释放。The problem is likely to be here:
You get objects copies with
ABRecordCopyValue
andABMultiValueCopyValueAtIndex
and they aren't released.