On 1/24/25 3:21 AM, Hairy Pixels via fpc-pascal wrote:
On Jan 24, 2025 at 2:10:53 AM, Santi via fpc-pascal
<fpc-pascal@lists.freepascal.org> wrote:
procedure foo()
var
s1: TStringList;
s2: TStringList;
s3: TStringList;
begin
s1:=TStringList.create;
try
s2:=TStringList.create;
try
s3:=TStringList.create;
try
doWhatever(s1,s2,s3)
finally
s3.free;
end;
finally
s2.free;
end;
finally
s1.free;
end
end;
Honestly this is the worst memory management strategy I've seen in any
language. It's more keywords than code! It was Delphi’s idea right? If
you’re making some UI app in 2025 a garbage collector or full ARC is
perfectly fine so I don’t see how they get away with selling this.
Maybe because there's a much better way to write it:
procedure foo();
var
s1: TStringList = nil;
s2: TStringList = nil;
s3: TStringList = nil;
begin
try
s1:=TStringList.create;
s2:=TStringList.create;
s3:=TStringList.create;
doWhatever(s1,s2,s3);
finally
FreeAndNil(s3);
FreeAndNil(s2);
FreeAndNil(s1);
end;
end;
Best regards,
Nikolay
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal