0

Apple에서 제공 한 API를 사용하여 AddressBook에서 레코드를 읽습니다.AddressBook에서 CFString을 사용할 때 메모리 관리

나는 아직도 메모리 관리에 대해 머리를 쓰고있다. 그래서 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); 

이 유일한 것은 내가 그들을 해제 여부를해야하는지 잘 모릅니다이다.

나는 메모리 관리를 더 잘 이해할 수 있도록 도와 주거나 올바른 방향으로 나를 가리키는 답변을 주시면 감사하겠습니다.

감사합니다.

답변

5

코어 파운데이션의 경험칙에 따르면 Copy 또는 Create을 포함하는 모든 함수는 이름을 공개 할 책임이있는 객체를 반환합니다. Apple의 Memory Management Guide for Core Foundation은 이것을 좀 더 자세히 설명합니다.

+0

감사합니다. 그냥 명확히하기 위해 CFString에서 NSString으로 캐스트 할 때 [string release] 또는 CFRelease (string)를 수행합니까? – Zebs

+0

사실,이 경우 CFString과 NSString이 "수신자 부담 브리지"이므로 정확히 똑같이 작동합니다. 나는 당신의 코드와 그것을 읽을 수있는 누구에게나 가장 명확하고 이해하기 쉬운 것을 사용합니다. –