如何对id <mtltexture>进行内存管理以将InvalidPtr无效*

时间:2018-07-31 05:31:26

标签: c# ios objective-c unity3d

我正在开发一个统一的ios插件。将iOS上的id<MTLTexture>发送到IntPtr统一发送。

IOS:

typedef struct
{
    void* texPtr;
}Ios_Struct;

id<MTLTexture> mtlTex;  // produced otherwhere, ARC

void foo_caller()
{
    ios_struct toBeSent;
    toBeSent.texPtr = (__bridge_retained void*)mtlTex;

    // call the callback that registered from Unity
    unityCallBack(toBeSent);

    // should I DO a release operation on the [toBeSent.texPtr]?
    // (__bridge_transfer id<MTLTexture>)toBeSent.texPtr;
}

团结:

public struct Unity_Struct;
{
    public IntPtr texPtr;
}

public delegate void Internal_Callback(Unity_Struct data);

// the callback that to be registered into IOS        
[MonoPInvokeCallback(typeof(Internal_Callback))]
private static void toBeCalled(Unity_Struct sentData)
{
    IntPtr texPtr = sentData.texPtr;

    // to use the texPtr
}

我想知道从id<MTLTexture>void*intPtr是否存在内存泄漏。

如果有,通过以下步骤释放toBeSent.texPtr是否正确:

// should I DO a release operation on the [toBeSent.texPtr]?
(__bridge_transfer id<MTLTexture>)toBeSent.texPtr;

0 个答案:

没有答案