考虑以下代码:
procedure Test;
var
MyPCharArray: array of PChar;
begin
SetLength(MyPCharArray, 3);
GetMem(MyPCharArray[0], 5);
GetMem(MyPCharArray[1], 5);
GetMem(MyPCharArray[2], 5);
StrCopy(MyPCharArray[0], 'test');
StrCopy(MyPCharArray[1], 'abcd');
StrCopy(MyPCharArray[2], '1234');
// Are these necessary?
FreeMem(MyPCharArray[0], 5);
FreeMem(MyPCharArray[1], 5);
FreeMem(MyPCharArray[2], 5);
end;
应该手动释放分配的元素,还是编译器会在MyPCharArray
超出范围时自动释放数组元素?