개발팡야
개발팡야

Reputation: 163

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

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?

Upvotes: 7

Views: 758

Answers (1)

Dalija Prasnikar
Dalija Prasnikar

Reputation: 28532

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'

Upvotes: 10

Related Questions