使用AddressBook的内存泄漏:泄漏对象“ABStyleProvider”

时间:2011-01-20 06:30:59

标签: iphone memory memory-leaks addressbook

我无法正确访问联系人的地址属性。我能够使用下面的方法成功访问电话号码或地址,但是当获得地址属性时,我得到一个泄漏,负责的框架是“+ [ABStyleProvider”。谁能告诉我这意味着什么或我做错了什么?

以下是ABPeoplePickerNavigationController内部。以下是我处理电话号码或地址选择的方法。我使用NSMutableString和CFDictionaryGetValueIfPresent来仅收集非空数据并将其作为字符串返回。

感谢您的帮助,我们将非常感谢任何建议。

if (person) {
if (property == kABPersonPhoneProperty){  
ABMultiValueRef phones = ABRecordCopyValue(person, kABPersonPhoneProperty); //Dane

if (phones) {

CFIndex index = ABMultiValueGetIndexForIdentifier(phones, identifier);
NSString *phone = (NSString*)ABMultiValueCopyValueAtIndex(phones, index);

//Set textField with Phone Number
MyTextField.text = phone;
[phone release];
CFRelease(phones);

[self doneEnteringPhoneNumber];
}

}
else if (property == kABPersonAddressProperty){
ABMultiValueRef addresses = ABRecordCopyValue(person, kABPersonAddressProperty); //Dane

if (addresses) {
CFIndex index = ABMultiValueGetIndexForIdentifier(addresses, identifier);
CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(addresses, index);

//Get Only valid address values (Non-Null)
CFTypeRef aString;
NSMutableString * address = [NSMutableString string];

if (CFDictionaryGetValueIfPresent(dict, kABPersonAddressStreetKey, &aString)){
 [address appendString:[NSString stringWithFormat:@"%@ ",(NSString *)aString]];
}
if (CFDictionaryGetValueIfPresent(dict, kABPersonAddressCityKey, &aString)){
 [address appendString:[NSString stringWithFormat:@"%@ ",(NSString *)aString]];  
}
if (CFDictionaryGetValueIfPresent(dict, kABPersonAddressStateKey, &aString)){
 [address appendString:[NSString stringWithFormat:@"%@ ",(NSString *)aString]];
}
if (CFDictionaryGetValueIfPresent(dict, kABPersonAddressZIPKey, &aString)){
 [address appendString:[NSString stringWithFormat:@"%@ ",(NSString *)aString]];
}

CFRelease(dict);

//Set Address
DestinationTextField.text = address; 

CFRelease(addresses);

//Auto trigger search for address
[self doneEnteringAddress];
}
}
}

作为后续,我完全删除了所有这些代码,并在以下情况下显示和解除了peoplePickerController: 1.如果选择了A Person 2.如果选择了A属性 3.如果用户取消 在每种情况下,我都会看到上面的内存泄漏。

仪器扩展泄漏细节:(16字节)。每次回到主视图时都会泄漏?

0 libSystem.B.dylib calloc
1 libobjc.A.dylib _internal_class_createInstanceFromZone
2 libobjc.A.dylib class_createInstance
3 CoreFoundation +[NSObject(NSObject) allocWithZone:]
4 CoreFoundation +[NSObject(NSObject) alloc]
5 CoreFoundation +[NSObject(NSObject) new]
6 AddressBookUI +[ABStyleProvider defaultStyleProvider]
7 AddressBookUI -[ABPeoplePickerNavigationController initAsAddressBook:withAddressBook:]
8 AddressBookUI -[ABPeoplePickerNavigationController init]
9 Cartis -[MainViewController getContactPhoneNumber:] ****************.m:707

10 CoreFoundation - [NSObject(NSObject)performSelector:withObject:withObject:]

这里也是我的PeoplePicker初始化和IBAction方法调用

ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
NSArray * displayedProperties = [NSArray arrayWithObjects:
                                 [NSNumber numberWithInt:kABPersonPhoneProperty],
                                 [NSNumber numberWithInt:kABPersonAddressProperty],
                                 nil];
picker.displayedProperties = displayedProperties;
//Dane - here
[self presentModalViewController:picker animated:YES];
[picker release];

2 个答案:

答案 0 :(得分:0)

希望以下链接有解决方案...... Memory leaks with AddressBook framework

答案 1 :(得分:0)

查看此帖子以获得解决方案; Memory leak with ABPeoplePickerNavigationController?