Registriert seit: 12. Aug 2003
Ort: Soest
4.027 Beiträge
Delphi 10.1 Berlin Enterprise
|
AW: Weak-TList ?
26. Feb 2015, 08:39
Delphi-Quellcode:
program WeakRefListTests;
uses
TestFramework,
TestInsight.DUnit,
Spring,
Spring.Collections;
type
TWeakRefListTest = class(TTestCase)
published
procedure ListDoesNotKeepStrongReference;
end;
IRefCounted = interface
function GetRefCount: Integer;
property RefCount: Integer read GetRefCount;
end;
TRefCounted = class(TInterfacedObject, IRefCounted);
procedure TWeakRefListTest.ListDoesNotKeepStrongReference;
var
sut: IList<WeakReference<IRefCounted>>;
ref: IRefCounted;
begin
sut := TCollections.CreateList<WeakReference<IRefCounted>>;
ref := TRefCounted.Create;
sut.Add(ref);
CheckEquals(1, ref.RefCount);
ref := nil;
CheckFalse(sut[0].IsAlive);
ref := sut[0];
CheckNull(ref);
end;
begin
RegisterTest(TWeakRefListTest.Suite);
RunRegisteredTests();
end.
|