As
SAKryukov correctly explained you must NOT explicitely delete what you allocated with
gcnew
. However the '
C++
function that returns
char *
' MIGHT require the deletion of the memory pointed by its return value. For instance, consider:
char * str;
str = new char[3];
sprintf(str, "hi");
String ^ result = gcnew (p);
delete [] str;
in the above code the
delete [] str;
statement is required (otherwise... memory leaks!), while you MUST NOT delete
result
, of course.