Chi*_*ron 0 iphone memory-management objective-c
你能看看我的代码吗:
(void)loadContactsFromAddressBook {
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex count = ABAddressBookGetPersonCount(addressBook);
ABRecordRef person;
for (int i = 0; i < count; i++) {
person = CFArrayGetValueAtIndex(allPeople, i);
CFStringRef cfStr = ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString* firstName = (NSString*) cfStr;
[contacts addObject:firstName];
CFRelease(cfStr);
}
CFRelease(addressBook);
CFRelease(allPeople);
}
Run Code Online (Sandbox Code Playgroud)
我在for block之后尝试了CFRelease(person),但是应用程序崩溃了"EXC_BAD_ACCESS".如果我删除CFRelease(人),该应用程序工作.
| 归档时间: |
|
| 查看次数: |
922 次 |
| 最近记录: |