我有一個接口的小問題。這裏是僞代碼:接口「遞歸」和引用計數
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實例並添加一個子項,那麼父類永遠不會被釋放。我明白爲什麼。我如何繞過它?
請參閱http://stackoverflow.com/questions/487311/how-to-implement-reference-counted-objects-in-delphi#487387,以獲得有關使用Delphi界面的循環引用問題的完整答案。 – 2012-02-01 17:28:15
使用真正的GC代替引用計數。 – 2008-11-24 18:40:25