pf8*_*f85 1 c objective-c core-foundation
考虑一些涉及错误处理的典型CF代码,比如说:
ABRecordRef aRecord = ABPersonCreate();
CFErrorRef anError = NULL;
ABRecordSetValue(aRecord, kABPersonFirstNameProperty, CFSTR("Joe"), &anError);
Run Code Online (Sandbox Code Playgroud)
anError这段代码后如何处理?我是否必须保留它,以确保它不会消失,然后再释放它?或者我已经是主人了,我只需要稍后发布它?
在Core Foundation框架中,调用者始终有责任释放通过CFErrorRef *参数返回的错误.例如,这是一个头文件注释来自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. */
Run Code Online (Sandbox Code Playgroud)
机会是AB框架使用相同的约定.