I cannot find any hint in the docs regarding object lifecycle management.
In the XPC service, do I have to keep a strong reference to the
NSXPCListener
, or does theresume
call take care of this effectively?I'm using Swift and a connection creation object to get most of the stuff out of the
main.swift
file:// main.swift if let dependencies = Dependencies().setUp() { // Actually run the service code (and never return) NSRunLoop.currentRunLoop().run() }
I have the hunch that the
dependencies
object (which creates theNSXPCListener
during set up) should keep a strong reference to the listener object. But theresume
method is said to work like operation queues.Conversely, does the client need to keep the
NSXPCConnection
around?In the XPC service, upon incoming connection, does setting
exportedObject
retain that object for the duration of the connection, or do I have to keep a strong ref to it myself?Consequently: When multiple connections come in, should I maintain a list of
exportedObject
s?In either the client of service, should I obtain a
remoteObjectProxy
once and keep it around, or should I obtain a proxy object anew for every call?My partcular XPC service is a launchd process running all the time, not a one-off thing, and the client app itself might run for a few hours in the background, too. I worry whether it's safe to keep a proxy object to the background service for a potentially long-running communication.
If background services crash, launchd is said to restart them. Now if my service was a "launch on demand" service instead, will message calls to proxy objects issue a relaunch if necessary, will obtaining a proxy object do, or will only reconnecting achieve that?
Thanks for helping me sort this out!