通过ABRecordSetValue返回CFErrorRef的内存管理 [英] Memory management of a CFErrorRef returned by ABRecordSetValue
问题描述
考虑一些典型的CF code,涉及错误处理,说是这样的:
Consider some typical CF code involving error handling, say something like this:
ABRecordRef aRecord = ABPersonCreate();
CFErrorRef anError = NULL;
ABRecordSetValue(aRecord, kABPersonFirstNameProperty, CFSTR("Joe"), &anError);
如何处理 anError
在此之后code?我必须把它保留下来,以确保它不会消失,再后来释放了吗?还是我已经拥有者,我只晚些时候发布呢?
How do I handle anError
after this code? Do I have to retain it, to make sure it doesn't go away, and then later release it? Or am I already the owner and I only have to release it later?
推荐答案
在核心基础架构,它总是调用者负责释放通过返回一个错误CFErrorRef *
论据。例如,以下是来自 CFBundle.h $一个头文件注释C $ C>
:
In the Core Foundation framework, it's always the caller's responsibility to release an error returned through a CFErrorRef *
argument. For example here's a header file comment from CFBundle.h
:
CF_EXPORT
Boolean CFBundlePreflightExecutable(CFBundleRef bundle, CFErrorRef *error) CF_AVAILABLE(10_5, 2_0);
/* This function will return true if the bundle is loaded, or if the bundle appears to be */
/* loadable upon inspection. This does not mean that the bundle is definitively loadable, */
/* since it may fail to load due to link errors or other problems not readily detectable. */
/* If this function detects problems, it will return false, and return a CFError by reference. */
/* It is the responsibility of the caller to release the CFError. */
机会是AB框架使用相同的约定。
Chances are the AB framework uses the same convention.
这篇关于通过ABRecordSetValue返回CFErrorRef的内存管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!