I am passing an array by reference from C# to C++/CLI to use as an out parameter. My code is as follows:
ushort a = new ushort;
void method(array<ushort>^% a)
a = gcnew array<ushort>(5);
a = 1;
a = 2;
a = 3;
Everything is being taken care of. Whether you're running C# or C++/CLI or any other .NET language for that matter, it's the same runtime that executes both under the hood. Therefore you get the same GC for both.
As you used
gcnew, you used the runtime's managed memory allocator. Had you used
new with an unmanaged array in C++/CLI, you'd have to free it with the
delete operator afterwards.