<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreFoundation",
  "identifier" : "/documentation/CoreFoundation/CFAllocator",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Core Foundation"
    ],
    "preciseIdentifier" : "c:@T@CFAllocatorRef"
  },
  "title" : "CFAllocator"
}
-->

# CFAllocator

```
class CFAllocator
```

## Overview

CFAllocator is an opaque type that allocates and deallocates memory for you. You never have to allocate, reallocate, or deallocate memory directly for Core Foundation objects—and rarely should you. You pass CFAllocator objects into functions that create objects; these functions have “Create” embedded in their names, for example, `CFStringCreateWithPascalString`. The creation functions use the allocators to allocate memory for the objects they create.

## Topics

### Creating an Allocator

[`CFAllocatorCreate(_:_:)`](/documentation/CoreFoundation/CFAllocatorCreate(_:_:))

Creates an allocator object.

### Managing Memory with an Allocator

[`CFAllocatorAllocate(_:_:_:)`](/documentation/CoreFoundation/CFAllocatorAllocate(_:_:_:))

Allocates memory using the specified allocator.

[`CFAllocatorDeallocate(_:_:)`](/documentation/CoreFoundation/CFAllocatorDeallocate(_:_:))

Deallocates a block of memory with a given allocator.

[`CFAllocatorGetPreferredSizeForSize(_:_:_:)`](/documentation/CoreFoundation/CFAllocatorGetPreferredSizeForSize(_:_:_:))

Obtains the number of bytes likely to be allocated upon a specific request.

[`CFAllocatorReallocate(_:_:_:_:)`](/documentation/CoreFoundation/CFAllocatorReallocate(_:_:_:_:))

Reallocates memory using the specified allocator.

### Getting and Setting the Default Allocator

[`CFAllocatorGetDefault()`](/documentation/CoreFoundation/CFAllocatorGetDefault())

Gets the default allocator object for the current thread.

[`CFAllocatorSetDefault(_:)`](/documentation/CoreFoundation/CFAllocatorSetDefault(_:))

Sets the given allocator as the default for the current thread.

### Getting an Allocator’s Context

[`CFAllocatorGetContext(_:_:)`](/documentation/CoreFoundation/CFAllocatorGetContext(_:_:))

Obtains the context of the specified allocator or of the default allocator.

### Getting the CFAllocator Type ID

[`CFAllocatorGetTypeID()`](/documentation/CoreFoundation/CFAllocatorGetTypeID())

Returns the type identifier for the CFAllocator opaque type.

### Callbacks

[`CFAllocatorAllocateCallBack`](/documentation/CoreFoundation/CFAllocatorAllocateCallBack)

A prototype for a function callback that allocates memory of a requested size.

[`CFAllocatorCopyDescriptionCallBack`](/documentation/CoreFoundation/CFAllocatorCopyDescriptionCallBack)

A prototype for a function callback that provides a description of the specified data.

[`CFAllocatorDeallocateCallBack`](/documentation/CoreFoundation/CFAllocatorDeallocateCallBack)

A prototype for a function callback that deallocates a block of memory.

[`CFAllocatorPreferredSizeCallBack`](/documentation/CoreFoundation/CFAllocatorPreferredSizeCallBack)

A prototype for a function callback that gives the size of memory likely to be allocated, given a certain request.

[`CFAllocatorReallocateCallBack`](/documentation/CoreFoundation/CFAllocatorReallocateCallBack)

A prototype for a function callback that reallocates memory of a requested size for an existing block of memory.

[`CFAllocatorReleaseCallBack`](/documentation/CoreFoundation/CFAllocatorReleaseCallBack)

A prototype for a function callback that releases the given data.

[`CFAllocatorRetainCallBack`](/documentation/CoreFoundation/CFAllocatorRetainCallBack)

A prototype for a function callback that retains the given data.

### Data Types

[`CFAllocatorContext`](/documentation/CoreFoundation/CFAllocatorContext)

A structure that defines the context or operating environment for an allocator (CFAllocator) object. Every Core Foundation allocator object must have a context defined for it.

### Constants

[Predefined Allocators](/documentation/CoreFoundation/predefined-allocators)

CFAllocator provides the following predefined allocators. In general, you should use `kCFAllocatorDefault` unless one of the special circumstances exist below.

## See Also

  [Memory Management Programming Guide for Core Foundation](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/CFMemoryMgmt.html#//apple_ref/doc/uid/10000127i)



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)