Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do TList<TPair<UInt32, UInt32>> need to be free?

Tags:

delphi

I wrote code

procedure Pair;
var
  PairList: TList<TPair<UInt32, UInt32>>;
  LPair: TPair<UInt32, UInt32>;
begin
  PairList := TList<TPair<UInt32, UInt32>>.Create;
  try
    PairList.Add(LPair.Create(4,10));
  finally
    PairList.Free;
  end;
end;

When I free the PairList, The Pair that I've created need to be freed too?

like image 637
개발팡야 Avatar asked Sep 14 '17 15:09

개발팡야


Video Answer


1 Answers

You don't have to free TPair variables, because it is a value type - record declared as

  TPair<TKey,TValue> = record
    Key: TKey;
    Value: TValue;
    constructor Create(const AKey: TKey; const AValue: TValue);
  end;

If you try releasing it with LPair.Free you would get compiler error

E2003 Undeclared identifier: 'Free'

like image 167
Dalija Prasnikar Avatar answered Oct 14 '22 07:10

Dalija Prasnikar