[vtkusers] Reference counting: when does vtk increment the count? how do I know?

Sean McBride sean at rogue-research.com
Thu Aug 3 12:39:10 EDT 2006


Hi all,

I have a question about vtk 5's memory management.  I know it uses
reference counting, and I am familiar with that system, but what's not
clear to me is which methods increment an object's reference count, and
when.  Consider:

vtkRenderWindowInteractor* interactor = ...
vtkInteractorStyleSwitch*	intStyle =
    vtkInteractorStyleSwitch::New();
cout << intStyle->GetReferenceCount(); // 1
interactor->SetInteractorStyle(intStyle);
cout << intStyle->GetReferenceCount(); // 2
intStyle->Delete();
cout << intStyle->GetReferenceCount(); // 1

The output is: 1, 2, 1.  But other than an educated guess or looking at
the source, how does one know that SetInteractorStyle() increments its
parameter's ref count?  It's docs say only "External switching between
joystick/trackball/new? modes".

I ask because I'd prefer to do 'intStyle->Delete()' as above instead of
keeping 'intStyle' around as a member variable in my own class.  And it
seems hard in general to know when I can and can't do that.

Thanks,

--
____________________________________________________________
Sean McBride, B. Eng                 sean at rogue-research.com
Rogue Research                        www.rogue-research.com 
Mac Software Developer              Montréal, Québec, Canada





More information about the vtkusers mailing list