我放
我声明
@property (nonatomic) ABAddressBookRef addressBook;
为类扩展的属性
-(void)dealloc
{
[[NSNotificationCenter defaultCenter]removeObserver:self];
CFRelease(self.addressBook);
}
然后在仅由 viewDidLoad 调用的函数中,我添加:-(void) vCreateAddressBookAndPopulateContact
{
self.addressBook = ABAddressBookCreate(); //will be released at dealloc
[self vPopulateContact];
}
它给了我警告:在分配时:
Object leaked: allocated object is not referenced later in this execution path and has a retain count of +1
解除分配时:
Incorrect decrement of the reference count of an object that is not owned at this point by the caller
所以我该怎么做?如何告诉编译器该对象稍后将在 dealloc 时被取消引用?
我希望我可以将那个 ABAddressBookRef 移到 ARC/NS 土地上。但是没有办法这样做。
self.addressBook 无法在函数中释放。那是因为如果我想添加或删除