Having the following generics class
TTuple<T1, T2> = class
protected
fItem1: T1;
fItem2: T2;
public
constructor Create; overload;
constructor Create(Item1: T1; Item2: T2); overload;
destructor Destroy; override;
property Item1: T1 read fItem1 write fItem1;
property Item2: T2 read fItem2 write fItem2;
end;
constructor TTuple<T1, T2>.Create;
begin
inherited;
end;
constructor TTuple<T1, T2>.Create(Item1: T1; Item2: T2);
begin
fItem1 := Item1;
fItem2 := Item2;
end;
destructor TTuple<T1, T2>.Destroy;
begin
inherited;
end;
and used in a manner like:
x := TTuple<TObjectList<TMyObjects>, Integer>.Create;
I need to free fitem1 manually. How can I free the fItem1 inside the destructor?
System.Generics.Collections
.TObjectList<T>
andTObjectDictionary<TKey,TValue>
will show you how the RTL uses the techniques outlined in @AndreiGalatyn response. – Begrime