這是我從AddressBook獲取Notes的代碼。從AddressBook獲取Notes時應用程序崩潰iphone
+(NSString*)getNote:(ABRecordRef)record {
return ABRecordCopyValue(record, kABPersonNoteProperty);
}
但在上面的實現中,我有內存泄漏。所以爲了消除內存泄露,我寫了下面的代碼
+(NSString*)getNote:(ABRecordRef)record {
NSString *tempNotes = (NSString*)ABRecordCopyValue(record, kABPersonNoteProperty);
NSString *notes = [NSString stringWithString:tempNotes];
[tempNotes release];
return notes;
}
如果我寫上面的代碼,我的應用程序崩潰。發生什麼事了?謝謝。
UPDATE:我把這種方法如下:
notes = [AddreesBook getNote:record];
其中筆記是我的伊娃&我在dealloc方法中釋放出來。
崩潰時它說什麼了...... – EmilioPelaez 2012-04-09 14:37:38