<!--
{
  "documentType" : "article",
  "framework" : "CoreMedia",
  "identifier" : "/documentation/CoreMedia/cmmemorypool-api",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "CMMemoryPool"
}
-->

# CMMemoryPool

An object that optimizes memory allocation when working with large blocks of memory.

## Discussion

An instance of `CMMemoryPool` is a memory allocation service that holds a pool of recently deallocated memory. Its purpose is to speed up subsequent allocations of the same size. Use this API in cases where you need to repeatedly allocate large blocks of memory, such as a video encoding app that outputs compressed data.

This object allocates memory by page. It doesn’t suballocate memory within pages, so don’t use it to allocate small blocks. For example, when calling the [`CMBlockBufferCreateWithMemoryBlock(allocator:memoryBlock:blockLength:blockAllocator:customBlockSource:offsetToData:dataLength:flags:blockBufferOut:)`](/documentation/CoreMedia/CMBlockBufferCreateWithMemoryBlock(allocator:memoryBlock:blockLength:blockAllocator:customBlockSource:offsetToData:dataLength:flags:blockBufferOut:)) function, you can use it as the `blockAllocator` argument, but not as the `structureAllocator` argument (use <doc://com.apple.documentation/documentation/CoreFoundation/kCFAllocatorDefault> instead).

When you no longer need to allocate memory from the pool, invalidate it by calling the [`CMMemoryPoolInvalidate(_:)`](/documentation/CoreMedia/CMMemoryPoolInvalidate(_:)) function, which tells the pool to stop holding memory for reuse.

> Note:
> A pool’s <doc://com.apple.documentation/documentation/CoreFoundation/CFAllocator> can outlive the pool itself. After you invalidate a memory pool, its <doc://com.apple.documentation/documentation/CoreFoundation/CFAllocator> instance allocates and deallocates with no pooling behavior.

A memory pool deallocates memory if it isn’t reused in `0.5` seconds, so that short-term peak usage doesn’t cause persistent bloat. You can override this period by specifying a value for [`kCMMemoryPoolOption_AgeOutPeriod`](/documentation/CoreMedia/kCMMemoryPoolOption_AgeOutPeriod). The system does this “aging out” during the pool’s <doc://com.apple.documentation/documentation/CoreFoundation/CFAllocatorAllocate(_:_:_:)> and <doc://com.apple.documentation/documentation/CoreFoundation/CFAllocatorDeallocate(_:_:)> calls.

## Topics

### Creating a Memory Pool

[`func CMMemoryPoolCreate(options: CFDictionary?) -> CMMemoryPool`](/documentation/CoreMedia/CMMemoryPoolCreate(options:))

Creates a memory pool.

### Managing a Memory Pool

[`func CMMemoryPoolGetAllocator(CMMemoryPool) -> CFAllocator`](/documentation/CoreMedia/CMMemoryPoolGetAllocator(_:))

Returns the allocator for the memory pool.

[`func CMMemoryPoolFlush(CMMemoryPool)`](/documentation/CoreMedia/CMMemoryPoolFlush(_:))

Deallocates all memory the pool holds.

[`func CMMemoryPoolInvalidate(CMMemoryPool)`](/documentation/CoreMedia/CMMemoryPoolInvalidate(_:))

Invalidates the memory pool, which causes its allocator to stop recycling memory.

### Accessing the Type Identifier

[`func CMMemoryPoolGetTypeID() -> CFTypeID`](/documentation/CoreMedia/CMMemoryPoolGetTypeID())

Returns the type identifier of memory pool objects.

### Data Types

[`class CMMemoryPool`](/documentation/CoreMedia/CMMemoryPool)

An instance that optimizes memory allocation when working with large blocks of memory.

### Errors

[`var kCMMemoryPoolError_AllocationFailed: OSStatus`](/documentation/CoreMedia/kCMMemoryPoolError_AllocationFailed)

An error that indicates the system failed to allocate an internal data structure.

[`var kCMMemoryPoolError_InvalidParameter: OSStatus`](/documentation/CoreMedia/kCMMemoryPoolError_InvalidParameter)

An error that indicates you called an API with an invalid parameter.



---

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)