当我有这导致如由仪器内存泄漏的方法,包括:Memoryleak使用CFRelease
-(BOOL)checkIfGroupExistWithName:(NSString*)groupName
{
BOOL hasGroup = NO;
//checks to see if the group is created ad creats group for Handheld contacts
CFErrorRef error = NULL;
ABAddressBookRef ab = ABAddressBookCreateWithOptions(NULL, &error);
CFIndex groupCount = ABAddressBookGetGroupCount(ab);
CFArrayRef allGroups = ABAddressBookCopyArrayOfAllGroups(ab);
for (int i=0; i<groupCount; i++) {
ABRecordRef group = CFArrayGetValueAtIndex(allGroups, i);
CFStringRef CFcurrentGroupName = ABRecordCopyCompositeName(group);
NSString *currentGroupName = (__bridge_transfer NSString *)CFcurrentGroupName;
if ([currentGroupName isEqualToString:groupName]) {
//!!! important - save groupID for later use
groupId = ABRecordGetRecordID(group);
hasGroup = YES;
i = (int) groupCount;
}
CFRelease(CFcurrentGroupName);
CFRelease(group);
}
return hasGroup;
}
如果使用CFRelease(AB);在返回hasGroup之前,它崩溃了。 我无法理解这里发生了什么。