<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreFoundation",
  "identifier" : "/documentation/CoreFoundation/CFMessagePortInvalidate(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Core Foundation"
    ],
    "preciseIdentifier" : "c:@F@CFMessagePortInvalidate"
  },
  "title" : "CFMessagePortInvalidate(_:)"
}
-->

# CFMessagePortInvalidate(_:)

Invalidates a CFMessagePort object, stopping it from receiving or sending any more messages.

```
func CFMessagePortInvalidate(_ ms: CFMessagePort!)
```

## Parameters

`ms`

The message port to invalidate.

## Discussion

Invalidating a message port prevents the port from ever sending or receiving any more messages; the message port is not deallocated, though. If the port has not already been invalidated, the port’s invalidation callback function is invoked, if one has been set with [`CFMessagePortSetInvalidationCallBack(_:_:)`](/documentation/CoreFoundation/CFMessagePortSetInvalidationCallBack(_:_:)). The [`CFMessagePortContext`](/documentation/CoreFoundation/CFMessagePortContext)  `info` information for `ms` is also released, if a release callback was specified in the port’s context structure. Finally, if a run loop source was created for `ms`, the run loop source is also invalidated.

---

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)