我有一个接口的小问题。这里是伪代码:接口“递归”和引用计数
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