<!--
{
  "availability" : [
    "iOS: 5.0.0 -",
    "iPadOS: 5.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.7.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "XPC",
  "identifier" : "/documentation/XPC/xpc_connection_set_finalizer_f(_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "XPC"
    ],
    "preciseIdentifier" : "c:@F@xpc_connection_set_finalizer_f"
  },
  "title" : "xpc_connection_set_finalizer_f(_:_:)"
}
-->

# xpc_connection_set_finalizer_f(_:_:)

Sets the finalizer for the connection.

```
func xpc_connection_set_finalizer_f(_ connection: xpc_connection_t, _ finalizer: xpc_finalizer_t?)
```

## Parameters

`connection`

The connection on which to set the finalizer.

`finalizer`

The function that will be invoked when the connection’s retain count has dropped to zero and is being torn down.

## Discussion

For many uses of context objects, this API allows for a convenient shorthand for freeing them. For example, for a context object allocated with `malloc(3)`:

```swift
xpc_connection_set_finalizer_f(object, free);
```

---

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)