My parent application uses helper XPC to achieve some task T1. XPC service is implemented using NSXPCConnection. Once the task is complete I don’t need this XPC to be alive. Hence, the parent process calls invalidate on NSXPCConnection object. But, the XPC is still alive even if the connection is invalid. I can see it getting listed in Activity Monitor.
How do I kill this XPC when parent app is still running and it does not require XPC to be alive?
XPC Agents by design are meant to be long lived. They automatically reload when they quit or crash based on their KeepAlive setting in the .plist configuration.
Maybe you can register as an Observer for NSWorkspace events:
see: NSWorkspace Workspace notifications are posted when:
Then you can disable your XPC Service When your Parent app quits and reenable it when it launches.