<!--
{
  "availability" : [
    "iOS: 10.0.0 -",
    "iPadOS: 10.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.12.0 -",
    "tvOS: 10.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 3.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "dnssd",
  "identifier" : "/documentation/dnssd/DNSServiceRefDeallocate(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "dnssd"
    ],
    "preciseIdentifier" : "c:@F@DNSServiceRefDeallocate"
  },
  "title" : "DNSServiceRefDeallocate(_:)"
}
-->

# DNSServiceRefDeallocate(_:)

Terminates a connection with the daemon and frees memory associated with the DNSServiceRef.

```
func DNSServiceRefDeallocate(_ sdRef: DNSServiceRef!)
```

## Parameters

`sdRef`

A DNSServiceRef initialized by any of the DNSService calls.

## Discussion

Any services or records registered with this DNSServiceRef will be deregistered. Any Browse, Resolve, or Query operations called with this reference will be terminated.

Note: If the reference’s underlying socket is used in a run loop or select() call, it should be removed BEFORE [`DNSServiceRefDeallocate(_:)`](/documentation/dnssd/DNSServiceRefDeallocate(_:)) is called, as this function closes the reference’s socket.

Note: If the reference was initialized with [`DNSServiceCreateConnection(_:)`](/documentation/dnssd/DNSServiceCreateConnection(_:)), any DNSRecordRefs created via this reference will be invalidated by this call - the resource records are deregistered, and their DNSRecordRefs may not be used in subsequent functions. Similarly, if the reference was initialized with [`DNSServiceRegister(_:_:_:_:_:_:_:_:_:_:_:_:)`](/documentation/dnssd/DNSServiceRegister(_:_:_:_:_:_:_:_:_:_:_:_:)), and an extra resource record was added to the service via [`DNSServiceAddRecord(_:_:_:_:_:_:_:)`](/documentation/dnssd/DNSServiceAddRecord(_:_:_:_:_:_:_:)), the DNSRecordRef created by the add call is invalidated when this function is called - the DNSRecordRef may not be used in subsequent functions.

Note: This call is to be used only with the DNSServiceRef defined by this API.

---

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)