Do TList <TPair <UInt32, UInt32 >> should be free?

I wrote the 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 release the PairList, should the couple I create also be released?

+5
source share
1 answer

You do not need to free TPair variables because it is a value type - a record declared as

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

If you try to free it with LPair.Free , you will get a compiler error

E2003 Undeclared identifier: "Free"

+9
source

Source: https://habr.com/ru/post/1271806/


All Articles