开发者

Memory management when using CFStrings from de AddressBook

开发者 https://www.devze.com 2023-01-26 00:54 出处:网络
I am reading records from the AddressBook using the Apple provided API. I am still getting my head around memory management and so CFStrings are confusing me at the moment.

I am reading records from the AddressBook using the Apple provided API.

I am still getting my head around memory management and so CFStrings are confusing me at the moment.

This is how I am getting the properties:

/开发者_开发技巧/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);

After that I use the values, the only thing is that I dont know if I should release them or not.

I would appreciate an answer that also helped me understand memory management better or that points me to the right direction.

Thank you!


The rule of thumb for Core Foundation is that any functions that include Copy or Create in their name will return an object that you are responsible for releasing. Apple's Memory Management Guide for Core Foundation explains this in a bit more detail.

0

精彩评论

暂无评论...
验证码 换一张
取 消