David Beck
David Beck

Reputation: 10159

Do I need to release CFError?

In Core Foundation, when I call a function with a CFError pointer, am I responsible to release that error afterwards? For example:

CFErrorRef error = NULL;
BOOL success = ABRecordSetValue(record, property, value, &error);
if (!success) {
    // handle error
    CFRelease(error);
}

I think I remember reading somewhere that this just magically works without the release, but can't find anything to verify that.

Upvotes: 1

Views: 786

Answers (1)

user529758
user529758

Reputation:

In CoreFoundation, if you get stuff back using a pointer, that's likely to have been allocated using one of the ...Create() functions (doesn't the documentation say anything about this?), so you do have to release it.

In Foundation, the "returned" values are autoreleased, so there you don't need to (and in fact should not) do this.

Upvotes: 3

Related Questions