Inline variable rzuca wyjątkiem

Inline variable rzuca wyjątkiem
LA
  • Rejestracja: dni
  • Ostatnio: dni
  • Postów: 477
0

Czesc,
testuje sobie najnowsze delphi 12.2 i tam sa te inline variables, ktore dla prostych typow dzialaja super, ale dla zlozonych juz nie...

Kod ponizej rzuca mi memory leak po wyjsciu z programu:

Kopiuj
begin
var JSONValue := TJSONObject.ParseJSONValue('jakis poprawny json');
end;

jak zadeklaruje kod po 'staropolsku', czyli z sekcją var powyzej begin to dziala.

to bug czy feature ;)?

KA
  • Rejestracja: dni
  • Ostatnio: dni
  • Lokalizacja: Gorlice
4

W Delphi 11 tak czy tak jest wyciek pamięci jeżeli nie wywołam JSONValue.Free;;

LA
  • Rejestracja: dni
  • Ostatnio: dni
  • Postów: 477
0

w tym linku jest nieco o tym:
https://docwiki.embarcadero.com/RADStudio/Sydney/en/Inline_Variable_Declaration

i sami podaja, ze....:
screenshot-20241223122253.png

stivens
  • Rejestracja: dni
  • Ostatnio: dni
1

A gdzie masz tam cos napisane o resourcach? Rzucilem na szybko okiem i nie ma nic o automagicznym zwalnianiu

EDIT: Mea culpa. Jednak jest cos o "Release" i "Destroy", ale bez dedykowanego rozdzialu

The effect is not limited only to visibility. A managed variable, like an interface reference or a record, will be properly cleaned up at the end of the block, rather than at the end of the procedure or method:

Kopiuj
procedure Test99;
begin

  // some code

  if (something) then
  begin
    var Intf: IInterface = GetInterface; // Intf.AddRef
    var MRec: TManagedRecord = GetMRecValue; // MRec.Create + MRec.Assign
    UseIntf(Intf);
    UseMRec(MRec);
  end; // Intf.Release and MRec.Destroy are implicitly called at end of scope
  
  // more code

end; // no additional cleanup

Zakladam, ze kluczowe sformulowanie jest tutaj:

rather than at the end of the procedure or method

Czyli jesli end procedure nie zwalnia danego obiektu, to ta konstrukcja tez nie

Zarejestruj się i dołącz do największej społeczności programistów w Polsce.

Otrzymaj wsparcie, dziel się wiedzą i rozwijaj swoje umiejętności z najlepszymi.