請你在我的代碼看看:爲什麼我在嘗試發佈時收到「EXC_BAD_ACCESS」?
(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);
}
我的塊但「EXC_BAD_ACCESS」應用程序崩潰後試圖CFRelease(人)。如果我刪除CFRelease(人),應用程序工作。
一般只有在調用release時,如果你已經'alloc''d,'init''d或'copy'' – PostMan 2010-11-07 22:55:41
AFAIK,我們也應該釋放Core基礎對象,我釋放addressBook和allPeople以及應用程序工作中。 – Chiron 2010-11-07 23:03:38
這是因爲方法名稱在名稱中具有「創建」或「複製」。 – 2010-12-31 23:20:51