CFAutoRelease()在iOS6上的行为 [英] CFAutoRelease() -like behavior on iOS6

查看:47
本文介绍了CFAutoRelease()在iOS6上的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个创建ABRecordRef,设置其属性并返回ref的方法.

I have a method that creates an ABRecordRef, sets its properties and returns the ref.

使用CFAutoRelease时遇到崩溃,因为我需要支持iOS< 7.我将如何适当地释放它?

I'm encountering a crash when I use CFAutoRelease because I need to support iOS <7. how would I go about to properly releasing this?

-(ABRecordRef) myRecord{
 ABRecordRef newRecord = ABPersonCreate();
//some setting here
return CFAutoRelease(newRecord); //how to release here?
}

推荐答案

对于CoreFoundation引用,我实际上不会在您的 myRecord 方法中释放该引用.相反,我将定义接口,以使 myRecord 的调用方拥有引用并负责释放该引用.

For CoreFoundation references, I actually wouldn't release that reference in your myRecord method. Instead I would define the interface such that the caller of myRecord owns the reference and is responsible for releasing it.

这篇关于CFAutoRelease()在iOS6上的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆