How to "switch-return" a NativeArray field?

When I do something like below, the console reports memory leak. So what’s the work around?

// Inside a system

NativeArray<myData> arrayApple;
NativeArray<myData> arrayPear;
NativeArray<myData> arrayOrange;
...

void Test(FruitType type)
{
var array = GetArray(type1)

// Do something with array
}

NativeArray<myType> GetArray(FruitType type)
{
return type switch
{
FruitType.Apple => arrayApple,
FruitType.Pear => arrayPear,
_ => arrayOrange,
};
}

This code isn’t related to the memory leak, because it doesn’t show where the array is allocated or where it is disposed.

1 Like

You’re right. It was not because of using this method. I will open another thread for my issue.