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?
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With