Search code examples
iosobjective-ccocoacore-foundation

Does CFMutableBitVectorRef need to be explicitly released?


As far as I can tell, foundation types that start with CF are C types and thus are not reference counted, is that correct? But as far as I can tell, there's no specific CFBitVectorRelease function.

I'm assuming they need to be released by calling CFRelease, would that be correct?


Solution

  • Core Foundation is a C API; there are no language-level objects.

    So while CF "Types" are not classes/objects, they act like objects (and several are actually interchangeable with Objective-C and Swift objects). Among their shared traits, they have reference counting (balancing the number of retains against the number of releases until they match and the type/object is deallocated).

    But since this is C, there is no built-in, automatic, or implied reference counting (e.g. ARC). So you're required to manually retain the type until you no longer need it, at which time you must call CFRelease to dispose of it. And Core Foundation does not have auto-release pools.

    Some types have a specific CFReleaseThisType() function. If a type has no specific release function, use CFRelease().

    It's all spelled out in the Core Foundation Memory Management guide.