[vtkusers] Reference counting in 6.3
Weiguang guan
guanw at rhpcs.mcmaster.ca
Fri Oct 23 16:24:38 EDT 2015
Hi Dan,
Thank you very much for the reply.
I still use the old way (vtkABC *v= vtkABC::New()) rather than using VTK
smart pointer. The reference counting mechanism of VTK must have changed
although I don't know when (which version) that happened.
The reference count of a VTK object used to be 1 right after its
creation. But now it is not always the case. I find source objects (like
vtkCubeSource, vtkImageEllipsoidSource, etc) have reference count = 2
right after being created while filter object have reference count = 1.
I haven't checked every class to see if there is an exception to the
above finding.
Here is a three-line code section together with running results:
vtkCubeSource* cube = vtkCubeSource::New(); //
ReferenceCount of cube = 2
vtkShrinkPolyData* shrink = vtkShrinkPolyData::New(); //
ReferenceCount of cube = 2, ReferenceCount of shrink= 1
shrink->SetInputConnection(cube->GetOutputPort()); // ReferenceCount of
cube = 2, ReferenceCount of shrink= 2
It can not be explained by the old VTK reference counting mechanism.
Best,
Weiguang
On 21/10/2015 3:11 PM, Dan Lipsa wrote:
> Hi Weiguang,
> Take a look at
> http://www.vtk.org/Wiki/VTK/Tutorials/SmartPointers
> This might clarify some of your questions. You have to remember that
> the reference count is stored in the objects themselves unlike the c++
> shared_ptr where the reference count is stored in the shared pointer
> object.
>
> For the first question: do you assign the object to a vtk smart
> pointer? That would explain why the reference count is 2.
> For the rest of the questions: when you set up the pipeline there are
> other objects involved besides the filter themselves, so it is harder
> to understand of the reference count.
>
> Also you can set VTK_DEBUG_LEAKS when you build VTK if you are
> concerned about leaks.
>
> Dan
>
>
> On Thu, Oct 15, 2015 at 4:13 PM, Weiguang guan
> <guanw at rhpcs.mcmaster.ca <mailto:guanw at rhpcs.mcmaster.ca>> wrote:
>
> Hello,
>
> I find, in debug mode, that the ReferenceCount of a
> vtkImageEllipsoidSource object becomes 2 right after being
> initiated (vtkImageEllipsoidSourc::New()). It should be 1 not 2,
> right? How could this happen?
>
> My second question is --- when you make a connection
> A->SetInputConnection(B->GetOutputPort()); Whose reference count
> will be increased by 1, A or B? I think B's reference count should
> be increased because it is used by A. But what I find is just the
> opposite.
>
> My third question is about setting up more than 1 connection for a
> filter. Taking vtkImageMathematics as an example, I do
> vtkImageMathematics* A = vtkImageMathematics::New();
> A->SetInputConnection(0, B1->GetOutputPort();
> A->SetInputConnection(0, B2->GetOutputPort();
>
> I find that the reference count of A gets increased by the first
> SetInputConnection() call only.
>
> Can someone explain how reference counting works in VTK? Thanks.
>
> Best,
> Weiguang
> _______________________________________________
> Powered by www.kitware.com <http://www.kitware.com>
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20151023/9a803f83/attachment.html>
More information about the vtkusers
mailing list