-(void) vCreateAddressBookAndPopulateContact
{
self.addressBook =ABAddressBookCreate();
}
+(void) vCreateAddressBookAndPopulateContact
{
[[RCABAddressBookHandler singleton] vCreateAddressBookAndPopulateContact];
//[self
}
代码是正确的。它创建了一个地址簿。当应用程序消失时,地址簿将在 dealloc 释放。
我确实有内存警告,我想知道我应该怎么做?
这就是属性的声明方式
@property (nonatomic) ABAddressBookRef addressBook;
我当然在 dealloc 释放它
-(void)dealloc
{
[[NSNotificationCenter defaultCenter]removeObserver:self];
CFRelease(_addressBook);
}
我们得到的警告是:
/business/Dropbox/badgers/RecentContact/RCABAddressBookHandler.m:52:1: Potential leak of an object
/business/Dropbox/badgers/RecentContact/RCABAddressBookHandler.m:51:23: Call to function 'ABAddressBookCreate' returns a Core Foundation object with a +1 retain count
/business/Dropbox/badgers/RecentContact/RCABAddressBookHandler.m:52:1: Object leaked: allocated object is not referenced later in this execution path and has a retain count of +1