Hmmm, I missed your response from a week ago. Sorry about that.
Back then you wrote:
my project disabled the ARC (not under my control)
)-:
If I send dictionary with content of xpc_dictionary_set_data
, will
retain keep the data memory from freeing immediately after releasing
the dictionary
I don’t understand what you’ve written here. If you want to clarify it, perhaps with some code snippets, I’d be happy to take another. In the meantime, here’s my general response…
The beauty of Objective-C reference counting — and XPC objects inherit this design — is that you can reason about memory management locally. So, if you allocate a data object, you are responsible for releases it. If you set that as a property of on a dictionary, the dictionary has to make a reference (or a copy) and it’s responsible for releasing that.
currently I'm sending data buffer to other side, I have to make a copy
of the data in receiver side to avoid recv side data copying crash
I don’t think you need to copy here — you could just as easily retain — but, yes, that’s the right approach. When your receive handler is called it’s passed a dictionary. The system holds a reference to that dictionary for the duration of the receive call. So, that dictionary, and any properties it references, are only guaranteed to persist until the point where you retain. If you need something to persist long, make a copy or add a reference.
(does xpc recv use the data copy or share the data reference/pointer
with sender?).
XPC can both copy data and share data at the VM layer, depending on the specific circumstances.
Today you wrote:
I'm sending surface instead and it is working
I/O Surface is definitely your friend.
How do I avoid IOSurfaceCreateXPCObject
crash?
It’s hard to tell from the snippet you posted. How do you construct surfaceObj
?
ps Please post your code snippets using a code block (use triple backquotes delimiters, or use the Code Block button). That makes it much easier to read and reason about.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"