インターフェイスに小さな問題があります。ここに擬似コードがあります:
type
Interface1 = interface
end;
Interface2 = interface
end;
TParentClass = class(TInterfacedObject, Interface1)
private
fChild : Interface2;
public
procedure AddChild(aChild : Interface2);
end;
TChildClass = class(TInterfacedObject, Interface2)
private
fParent : Interface2;
public
constructor Create(aPArent : Interface1);
end;
誰でも欠陥を見ることができますか?子がその親への参照を持つ必要がありますが、この状況では参照カウントが機能しません。ParentClass インスタンスを作成して子を追加すると、親クラスは解放されません。理由がわかります。どうすればそれを回避できますか?