---
title: NSMakeCollectable
framework: foundation
role: symbol
role_heading: Function
path: foundation/nsmakecollectable
---

# NSMakeCollectable

Makes a newly allocated Core Foundation object eligible for collection.

## Declaration

```occ
static idNSMakeCollectable(CFTypeRef cf);
```

## Discussion

Discussion 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

### Legacy

- [NSGarbageCollector](foundation/nsgarbagecollector.md)
- [NSAllocateCollectable](foundation/nsallocatecollectable.md)
- [NSReallocateCollectable](foundation/nsreallocatecollectable.md)
- [Memory Allocation Options](foundation/1539826-memory-allocation-options.md)
