使用来自德通讯录CFStrings当内存管理
-
27-09-2019 - |
题
我使用的苹果公司提供的API读取来自地址簿记录。
我仍然得到我的头左右的内存管理等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);
在我使用的值,唯一的事情是,我不知道我是否应该释放它们。
我会很感激的答案也让我了解到的内存管理更好或点我到正确的方向。
谢谢!
解决方案
拇指核心基础的规则是,包括他们的名字Copy
或Create
任何函数会返回一个对象,你是负责释放。苹果公司的内存管理指南核心基础解释这一点的更多细节。
不隶属于 StackOverflow