[vtkusers] create and delete vtkActor and vtk3DWidget

Weiguang guan guanw at rhpcs.mcmaster.ca
Thu Feb 25 15:51:22 EST 2016


Hello,

In my program (C++), a user can create/remove an object (cone, cylinder, 
...) or a widget (vtkBoxWidget, ...). What's the right way of doing so 
without causing memory leaking or trashing?

In "Examples/Tutorial/Step6/Cxx/Cone6.cxx", I see the last section of 
code doing clean-up at the end as follows:
  170   cone->Delete();
  171   coneMapper->Delete();
  172   coneActor->Delete();
  173   callback->Delete();
  174   boxWidget->Delete();
  175   ren1->Delete();
  176   renWin->Delete();
  177   iren->Delete();
  178   style->Delete();
when it exits.

Lines 170-172 won't delete coneActor because ren1 still use it 99 
ren1->AddActor( coneActor ). This example works fine as it delete ren1, 
renWin, and iren as well at exit point. Shall I do
ren1-RemoveActor(coneActor) in addtion to coneActor->Delete()? I just 
want to "undo" the creation as if cone had never been created.

How about the widget boxWidget? It may be trickier. In addition to 
boxWidget->Delete(), do I need to do something like
boxWidget->SetInteractor(NULL);
boxWidget->UnRegister(iren);
?

Weiguang



More information about the vtkusers mailing list