[vtkusers] Reference counting not work !!!

Volpe, Christopher R (CRD) volpecr at crd.ge.com
Tue Feb 6 17:34:01 EST 2001

|> >vtkConeSource cone
|> >   cone SetResolution 8
|> >vtkPolyDataMapper coneMapper
|> >   coneMapper SetInput [cone GetOutput]
|> >vtkActor coneActor
|> >   coneActor SetMapper coneMapper
|> >
|> >cone Delete
|> >
|> >[coneMapper GetInput] GetReferenceCount
|> >
|> >and I do not understand why the result of the last command is 2...
|> >wouldn't the result must be 1?

  I'm confused by what you say below. Perhaps you can clarify the following:

|> The output of vtkConeSOurce (a vtkPolyData) refers to its generating 
|> process object (the vtkDataObject::SetSource() method). So 
|> when the object 
|> is created, its reference count is 1,

Ok, the "object" here that we're concerned about, is the PolyData object. It's created by the cone
source, and the cone source "owns" (so to speak) the first reference to it.

|> then the data object 
|> registers it so 
|> the count goes to 2,

Wait a second, the "it" here in "registers it" *IS* the data object, i.e. the PolyData. The objects
don't register themselves, do they?

|> and then the coneMapper SetInput() 
|> brings it to 3. 

Presuming the PolyData doesn't register itself, it should be 2 at this point. The count shouldn't get
to three.

|> Your delete brings it back down to 2.

Perhaps I'm misunderstanding something, but what I think is happening is this:

1) ConeSource is created, and ConeSource's ref count (which until now we have not talked about) is 1.
2) ConeSource creates PolyData, PolyData's ref count is 1. PolyData registers its source,
ConeSource's ref count bumped up to 2.
3) ConeMapper's input is set to the PolyData. ConeMapper registers the PolyData, bumping PolyData's
ref count to 2.
4) User invokes Delete on ConeSource. ConeSource's ref count decreased from 2 to 1. But since
ConeSource's ref count isn't dropped to zero, it still exists, and therefore it's hold on the
PolyData doesn't change, and therefore the PolyData's ref count stays at 2.

Is this correct, Will? Or have I missed something? I've verified experimentally that the refcount on
the PolyData never reaches 3. It it 2 immediately before and immediately after the "cone Delete"

> g GE Corporate Research & Development 
> ______________________________________________________________________
> ______________________________________________________________________
> ______
Christopher R. Volpe
Computer Scientist
Visual Information Program
Bldg KW, Room C215
P.O. Box 8, Schenectady, NY 12301

(518) 387-7766, Dial Comm: 8*833-7766, Fax: (518) 387-6981
e-mail: volpecr at crd.ge.com    web: http://www.crd.ge.com/~volpecr

More information about the vtkusers mailing list