---
title: "xpc_connection_set_finalizer_f(_:_:)"
framework: xpc
role: symbol
role_heading: Function
path: "xpc/xpc_connection_set_finalizer_f(_:_:)"
---

# xpc_connection_set_finalizer_f(_:_:)

Sets the finalizer for the connection.

## Declaration

```swift
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

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): xpc_connection_set_finalizer_f(object, free);

## See Also

### Context

- [xpc_connection_set_context(_:_:)](xpc/xpc_connection_set_context(_:_:).md)
- [xpc_connection_get_context(_:)](xpc/xpc_connection_get_context(_:).md)
- [xpc_finalizer_t](xpc/xpc_finalizer_t.md)
