A very simple question:
type
TMyRecord = Record
Int: Integer;
Str: String;
end;
PMyRecord = ^TMyRecord;
var
Data: PMyRecord;
begin
New(Data);
Data.Int := 42;
Data.Str := 'Test';
Dispose(Data);
end;
My question is, am I creating a memory leak here (with the String
)? Should I call Data.Str := '';
before calling Dispose
?
Thanks!
No, Dispose
properly frees strings and dynamic arrays in records, including nested ones. GetMem
/FreeMem(Data)
would create a memory leak, indeed.