0

我正在使用 Apple 提供的 API 从 AddressBook 中读取记录。

我仍然在考虑内存管理,所以现在让我CFStrings很困惑。

这就是我获取属性的方式:

//Get Basic properties
NSString* firstName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString* lastName = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
NSNumber* record = [NSNumber numberWithInt:ABRecordGetRecordID(person)];

//Build Full Name
NSString* fullName=[self fullNameWith:firstName and:lastName];

//Get Phone number and Label
ABMultiValueRef phone = ABRecordCopyValue(person, property);
    //Turn identifier into index
CFIndex index = ABMultiValueGetIndexForIdentifier(phone, identifier);
    //Get the value and the label using the index
NSString *value =(NSString *)ABMultiValueCopyValueAtIndex(phone, index);
CFStringRef label = ABMultiValueCopyLabelAtIndex(phone, index);
    //Get the localized value of hte label
NSString * localizedLabel = (NSString *)ABAddressBookCopyLocalizedLabel(label);

之后我使用这些值,唯一的事情是我不知道我是否应该释放它们。

我会很感激一个答案,它也帮助我更好地理解内存管理或者指出我正确的方向。

谢谢!

4

1 回答 1

5

Core Foundation 的经验法则是,任何包含CopyCreate在其名称中的函数都将返回一个您负责释放的对象。Apple 的Core Foundation 内存管理指南更详细地解释了这一点。

于 2010-11-22T04:06:04.823 回答