Hi
I was wondering how Delphi allocates and frees memory for string types. I remember hearing somewhere that strings are reference counted, but what would happen if I put a string in something like a record like this:
type
TMyRec = record
X, Y : Integer;
Str : string;
end;
PMyRec = ^TMyRec;
var
MyRec: PMyRec;
begin
New(MyRec);
// Do some stuff with MyRec
Dispose(MyRec);
end;
Would the Str field strictly be a valid and usable string after the call to New and would memory be freed after the call to Dispose? I have the same question for dynamic arrays in Delphi. Could usage like this result in memory leaks?
Eon
I was wondering how Delphi allocates and frees memory for string types. I remember hearing somewhere that strings are reference counted, but what would happen if I put a string in something like a record like this:
type
TMyRec = record
X, Y : Integer;
Str : string;
end;
PMyRec = ^TMyRec;
var
MyRec: PMyRec;
begin
New(MyRec);
// Do some stuff with MyRec
Dispose(MyRec);
end;
Would the Str field strictly be a valid and usable string after the call to New and would memory be freed after the call to Dispose? I have the same question for dynamic arrays in Delphi. Could usage like this result in memory leaks?
Eon