Makes a newly allocated Core Foundation object eligible for collection.


id NSMakeCollectable(CFTypeRef cf);


This function is a wrapper for CFMakeCollectable, but its return type is id—avoiding the need for casting when using Cocoa objects.

This function may be useful when returning Core Foundation objects in code that must support both garbage-collected and non-garbage-collected environments, as illustrated in the following example.

- (CFDateRef)foo {
    CFDateRef aCFDate;
    // ...
    return [NSMakeCollectable(aCFDate) autorelease];

CFTypeRef style objects are garbage collected, yet only sometime after the last CFRelease is performed. Particularly for fully-bridged CFTypeRef objects such as CFStrings and collections (such as CFDictionary), you must call either CFMakeCollectable or the more type safe NSMakeCollectable, preferably right upon allocation.

See Also



A convenient interface to the garbage collection system.


Allocates collectable memory.


Reallocates collectable memory.

Memory Allocation Options

Constants used to control behavior when allocating or reallocating collectible memory.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software