我写了代码
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;当我释放PairList时,我创建的一对也需要被释放?
发布于 2017-09-14 16:02:31
您不必释放TPair变量,因为它是一个声明为
TPair<TKey,TValue> = record
Key: TKey;
Value: TValue;
constructor Create(const AKey: TKey; const AValue: TValue);
end;如果您尝试用LPair.Free发布它,就会得到编译器错误。
E2003未声明标识符:“空闲”
https://stackoverflow.com/questions/46223627
复制相似问题