I am passing an array by reference from C# to C++/CLI to use as an out parameter. My code is as follows:
C#
ushort[] a = new ushort[1];
cppclr.method(ref a);
C++/CLI
void method(array<ushort>^% a)
{
a = gcnew array<ushort>(5);
a[0] = 1;
a[1] = 2;
a[2] = 3;
}
The code compiles fine and produces no error. However, I am confused whether the array that I created in C# has been taken care of by the garbage collection? My confusion is that since I am assigning a new memory inside C++/CLI, the previous reference is lost and should be handled by garbage collection. The program doesn't show any memory leaks. Do I need to take care of this situation in any other way?