CFRelease
預計非NULL指針。你可以檢查與一個if
聲明,但它更容易簡單地釋放或自動釋放friendLastName
代替:
CFStringRef lastNameRef = ABRecordCopyValue((ABRecordRef)personRecordRef, kABPersonLastNameProperty);
NSString *friendLastName = (NSString*)lastNameRef;
// use friendLastName
[friendLastName release];
或
CFStringRef lastNameRef = ABRecordCopyValue((ABRecordRef)personRecordRef, kABPersonLastNameProperty);
NSString *friendLastName = (NSString*)lastNameRef;
[friendLastName autorelease];
// use friendLastName
你似乎不使用lastNameRef
,你也可以內聯變量:
NSString *friendLastName = (NSString*)ABRecordCopyValue((ABRecordRef)personRecordRef, kABPersonLastNameProperty);
// use friendLastName
[friendLastName release];
或
NSString *friendLastName = (NSString*)ABRecordCopyValue((ABRecordRef)personRecordRef, kABPersonLastNameProperty);
[friendLastName autorelease];
// use friendLastName
在調用'CFRetain()'或'CFRelease()'之前,您必須*總是*執行此操作。這是這些職能合同的一部分。 –