Plugin interop thread safety and resource management

Hi,

I’ve written a few simple plugins for iOS, and they’ve worked, but there are two related questions which remain unresolved to me, which cause me discomfort when I think about them. Namely,

#1 When unity calls iOS native code, does it do so within the main execution thread? Specifically, when I access my Obective-C code from my extern "C" functions, can I simply call the necessary functions, or should I performSelectorOnMainThread?

#2 When I send structs, strings, and arrays to and from Unity, whose responsibility is it to delete/release them later? If I do need to worry about it, can you provide some examples for the most common data types?

I’ve read the mono interop guide, but it’s fairly complex, and I’m not sure I got everything it was trying to relay. Neither am I aware of how fully it describes the way Unity’s implementation works.

Thanks!

#1 There is no delay when a native method is invoked, it is from the main thread, unless said method is invoked manually from another thread. You can make your own thread in the managed code…

#2 It is up to you to clean your memory in the native side. The managed object is handled by the Garbage collector, as usual, but the memory allocation you did on the native still need to be cleaned manually.

Thanks LightStriker for confirming!