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

Paul Tait - OPES Paul at opes.com.au
Fri Aug 4 02:01:21 EDT 2006


The way I think off it is that whenever I instantiate and object the count
is "1". Whenever I use that object in a Set???() method of another object
the count gets incremented. At that point I can ->Delete() the original
object but it won't get destroyed till all the other objects get
->Delete()'ed. I agree that this means a lot of objects can created and
deleted on the fly without creating class variables.

Paul Tait

-----Original Message-----
From: vtkusers-bounces+paul=opes.com.au at vtk.org
[mailto:vtkusers-bounces+paul=opes.com.au at vtk.org] On Behalf Of Sean McBride
Sent: Friday, 4 August 2006 12:39 AM
To: vtkusers at vtk.org
Subject: [vtkusers] Reference counting: when does vtk increment the count?
how do I know?


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


_______________________________________________
This is the private VTK discussion list. 
Please keep messages on-topic. Check the FAQ at:
http://www.vtk.org/Wiki/VTK_FAQ Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers

-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.394 / Virus Database: 268.10.5/406 - Release Date: 2/08/2006
 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.394 / Virus Database: 268.10.5/407 - Release Date: 3/08/2006
 




More information about the vtkusers mailing list