Which NSXPCConnection related objects do I have to retain myself?
Asked Answered
L

0

6

I cannot find any hint in the docs regarding object lifecycle management.

  1. In the XPC service, do I have to keep a strong reference to the NSXPCListener, or does the resume 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 the NSXPCListener during set up) should keep a strong reference to the listener object. But the resume method is said to work like operation queues.

  2. Conversely, does the client need to keep the NSXPCConnection around?

  3. 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?

  4. Consequently: When multiple connections come in, should I maintain a list of exportedObjects?

  5. 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!

Ligature answered 20/3, 2015 at 9:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.