<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreFoundation",
  "identifier" : "/documentation/CoreFoundation/CFBinaryHeapCallBacks/retain",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "Core Foundation"
    ],
    "preciseIdentifier" : "c:@SA@CFBinaryHeapCallBacks@FI@retain"
  },
  "title" : "retain"
}
-->

# retain

Callback function used to retain a value being added to a binary heap.

```
var retain: ((CFAllocator?, UnsafeRawPointer?) -> UnsafeRawPointer?)!
```

## Parameters

`allocator`

The binary heap’s allocator.

`ptr`

The value to retain.

## Return Value

The value to store in the binary heap, which is usually the `ptr` parameter passed to this callback, but may be a different   value if a different value should be stored in the binary heap.

## Discussion

The callback used to add a retain for the binary heap on values as they are put into the binary heap. This callback returns the value to use as the value in the binary heap, which is usually the value parameter passed to this callback, but may be a different value if a different value should be added to the binary heap. If this field is `NULL`, the binary heap does nothing to retain a value being added.

---

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)