デ・アドレス帳から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);
私は値を使用した後、は、唯一のものは、私は彼らを解放したりべきではない場合、私は知らないということです。
私も、私はより良いメモリ管理を理解したり、右方向へのポイントに私を助けたという答えをお願い申し上げます。
ありがとうございます!
解決
Core Foundationのための親指のルールは、自分の名前でCopy
またはCreate
を含むすべての機能を使用すると、解除するための責任があるオブジェクトを返すことです。 Appleの<のhref = "http://developer.apple.com/library/ios/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html#//apple_ref/doc/uid/20001148-CJBEJBHH" のrel = "nofollowを「>もう少し詳細にこれを説明する Core Foundationのためのメモリ管理ガイドます。
所属していません StackOverflow