[vtkusers] a question about cross-reference in vtk
wwyang
wwyang at cad.zju.edu.cn
Mon Aug 28 22:41:16 EDT 2006
There are two classes which are refered by each other:
class CVTKHost : public vtkObject{
...
vtkSetObjectMacro(Client, CVTKClient);
...
CVTKClient *Client;
}
class CVTKClient : public vtkObject{
...
vtkSetObjectMacro(Host, CVTKHost);
...
CVTKHost *Host;
}
I use them as follows:
CVTKHost *pHost = CVTKHost::New();
CVTKClient *pClient = CVTKClient::New();
pHost->SetClient(pClient);
pClient->SetHost(pHost);
pHost->Delete();
pClient->Delete();
Because they are referred by each other, a dead lock occurs in the above code, which causes
objects pointered by pHost&pClient will not be released.
One way to resolve it is to re-arrange above codes as:
...
pHost->SetClient(pClient);
pClient->SetHost(pHost);
pHost->SetClient(NULL);
pClient->SetHost(NULL);
pHost->Delete();
pClient->Delete();
but it's tedious.
Anybody knows more better way to resolve this condition in vtk? I know the classes of vtkAlgorithm
and vtkExecutive are also cross-referred, and Register(), UnRegister() methods in them are overridden with
garbage collection mechanism in vtk. But i donna understand this mechanism so clearly that i donna know
whether it's the way to resolve this problem in vtk.
Appreciate any advice.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20060829/0806d7e8/attachment.htm>
More information about the vtkusers
mailing list