El 16/10/2024 a las 19:03, Guillermo Martínez Jiménez via fpc-pascal escribió:
Prease DON'T add garbage collector.  IMO it isn't a good idea.  I had
very bad experiences with it. Unless somebody found a new magic
algorithm in the last decade...

El Wed, 16 Oct 2024 04:49:44 -0700
Hairy Pixels via fpc-pascal<fpc-pascal@lists.freepascal.org>  escribió:
Not a garbage collector but an autofree when the objects gets out of scope would be handy

procedure foo()
var
 s: *auto *TStringList;
begin
 s:=TStringList.create;
 doWhatever(s);
end;

would be equivalent to

procedure foo()
var
 s: TStringList;
begin
 s:=TStringList.create;
 try
   doWhatver(s);
 finally
   s.free;
 end
end;

Think of it, which one is more readable?

procedure foo()
var
 s1: *auto *TStringList;
 s2: *auto *TStringList;
 s3: *auto *TStringList;
begin
 s1:=TStringList.create;
 s2:=TStringList.create;
s3:=TStringList.create;
doWhatever(s1,s2,s3);
end;

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;




_______________________________________________
fpc-pascal maillist  -fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


--
Saludos
Santi
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to