I use this code to get the last name of ABPerson
CFStringRef lastNameRef = ABRecordCopyValue((ABRecordRef)personRecordRef, kABPersonLastNameProperty);
NSString *friendLastName = (NSString*)lastNameRef;
CFRelease(lastNameRef);
it work fine when the value of last name is not equal to NULL but when the this value is NULL the application crash at the third line because I try to relese NULL
the question is witch is the best way to releasing the CFString in this case without causing the crash of the application
Just use an if to check for NULL.
if (lastNameRef != NULL)
CFRelease(lastNameRef);
CFRelease is old C style code. One should check for NULL before calling CFRelease as also set lastNameRef to NULL after calling CFRelease.
if (lastNameRef != NULL)
{
CFRelease(lastNameRef);
lastNameRef = NULL;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With