<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">Hi Dan,<br>
      <br>
      Thank you very much for the reply. <br>
      <br>
      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. <br>
      <br>
      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.<br>
      <br>
      Here is a three-line code section together with running results:<br>
      vtkCubeSource* cube = vtkCubeSource::New();                    //
      ReferenceCount of cube = 2<br>
      vtkShrinkPolyData* shrink = vtkShrinkPolyData::New();     //
      ReferenceCount of cube = 2, ReferenceCount of shrink= 1<br>
      shrink->SetInputConnection(cube->GetOutputPort());        
      // ReferenceCount of cube = 2, ReferenceCount of shrink= 2<br>
      It can not be explained by the old VTK reference counting
      mechanism.<br>
      <br>
      Best,<br>
      Weiguang<br>
      <br>
      On 21/10/2015 3:11 PM, Dan Lipsa wrote:<br>
    </div>
    <blockquote
cite="mid:CADwGrVqgucZz6f6C7+GEug13t2=yauE2WQQg_pot3w1UbPYWRA@mail.gmail.com"
      type="cite">
      <div dir="ltr">Hi Weiguang,
        <div>Take a look at </div>
        <div><a moz-do-not-send="true"
            href="http://www.vtk.org/Wiki/VTK/Tutorials/SmartPointers">http://www.vtk.org/Wiki/VTK/Tutorials/SmartPointers</a><br>
        </div>
        <div>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.</div>
        <div><br>
        </div>
        <div>For the first question: do you assign the object to a vtk
          smart pointer? That would explain why the reference count is
          2.</div>
        <div>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.</div>
        <div><br>
        </div>
        <div>Also you can set VTK_DEBUG_LEAKS when you build VTK if you
          are concerned about leaks.</div>
        <div><br>
        </div>
        <div>Dan</div>
        <div><br>
        </div>
      </div>
      <div class="gmail_extra"><br>
        <div class="gmail_quote">On Thu, Oct 15, 2015 at 4:13 PM,
          Weiguang guan <span dir="ltr"><<a moz-do-not-send="true"
              href="mailto:guanw@rhpcs.mcmaster.ca" target="_blank">guanw@rhpcs.mcmaster.ca</a>></span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
            <br>
            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?<br>
            <br>
            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.<br>
            <br>
            My third question is about setting up more than 1 connection
            for a filter. Taking vtkImageMathematics as an example, I do<br>
            vtkImageMathematics* A = vtkImageMathematics::New();<br>
            A->SetInputConnection(0, B1->GetOutputPort();<br>
            A->SetInputConnection(0, B2->GetOutputPort();<br>
            <br>
            I find that the reference count of A gets increased by the
            first SetInputConnection() call only.<br>
            <br>
            Can someone explain how reference counting works in VTK?
            Thanks.<br>
            <br>
            Best,<br>
            Weiguang<br>
            _______________________________________________<br>
            Powered by <a moz-do-not-send="true"
              href="http://www.kitware.com" rel="noreferrer"
              target="_blank">www.kitware.com</a><br>
            <br>
            Visit other Kitware open-source projects at <a
              moz-do-not-send="true"
              href="http://www.kitware.com/opensource/opensource.html"
              rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
            <br>
            Please keep messages on-topic and check the VTK FAQ at: <a
              moz-do-not-send="true"
              href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer"
              target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
            <br>
            Search the list archives at: <a moz-do-not-send="true"
              href="http://markmail.org/search/?q=vtkusers"
              rel="noreferrer" target="_blank">http://markmail.org/search/?q=vtkusers</a><br>
            <br>
            Follow this link to subscribe/unsubscribe:<br>
            <a moz-do-not-send="true"
              href="http://public.kitware.com/mailman/listinfo/vtkusers"
              rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a><br>
          </blockquote>
        </div>
        <br>
      </div>
    </blockquote>
    <br>
  </body>
</html>