Slicer3:VTK Leak Debugging

From NAMIC Wiki
Revision as of 18:49, 27 January 2007 by Pieper (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Home < Slicer3:VTK Leak Debugging

If you are getting leaks for a vtkObject but can't figure out where it's coming from, you can try making a change to the constructor for that class and checking the debug output (warning, it can be verbose). What you will see from the following type of change is instances that are created but never destroyed. Then you can add other debug statements in your code and narrow down which instances aren't being deleted.

Add this at the beginning of the constructor:

this->DebugOn();
vtkDebugMacro("constructing");

and this in the destructor:

vtkDebugMacro("destructing");

For example, these changes helped me find an extra instance of vtkPoints

// Construct object with an initial data array of type float.
vtkPoints::vtkPoints(int dataType)
{
this->DebugOn();
vtkDebugMacro("constructing");
  this->Data = vtkFloatArray::New();
  this->Data->Register(this);
  this->Data->Delete();
  this->SetDataType(dataType);

  this->Data->SetNumberOfComponents(3);

  this->Bounds[0] = this->Bounds[2] = this->Bounds[4] = 0.0;
  this->Bounds[1] = this->Bounds[3] = this->Bounds[5] = 1.0;
}

vtkPoints::~vtkPoints()
{
vtkDebugMacro("destructing");
  this->Data->UnRegister(this);
}