<div dir="ltr">Hi, everyone!<br><br>I am a new VTK user and trying to figure out how vtk reference counting is working.<br>When I saw the result of simple code, I was kind of surprised.<br><br>This is the sample code that I used to test reference counting.<br>
<br>// test for reference counting<br>&nbsp;&nbsp;&nbsp; vtkImageData* vtkImage = vtkImageData::New();<br>&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; &quot;Reference count: &quot; &lt;&lt; vtkImage-&gt;GetReferenceCount() &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; &quot;Reference count: &quot; &lt;&lt; vtkImage-&gt;GetReferenceCount() &lt;&lt; std::endl;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp; vtkImageReslice* reslicer = vtkImageReslice::New();<br>&nbsp;&nbsp;&nbsp;&nbsp; reslicer-&gt;SetInput (vtkImage);<br>&nbsp;&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; &quot;Reference count: &quot; &lt;&lt; vtkImage-&gt;GetReferenceCount() &lt;&lt; std::endl;<br>
&nbsp;&nbsp;&nbsp;&nbsp; reslicer-&gt;Update();<br>&nbsp;&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; &quot;Reference count: &quot; &lt;&lt; vtkImage-&gt;GetReferenceCount() &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp;&nbsp; reslicer-&gt;Delete();&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; &quot;Reference count: &quot; &lt;&lt; vtkImage-&gt;GetReferenceCount() &lt;&lt; std::endl;<br>
<br><br>The output was 1 1 3 3 3!!!<br>It seems like the reference count increases before the actual pipeline finishes updating.<br><br>I always thought that if the container(reslicer) is deleted, the reference count of vtkImage&nbsp; decreases as a result. And why did the reference become 3 instead of 2?<br>
Am I thinking wrong? Could anyone explain about this?<br><br>Thank you so much.<br><br>Sincerely,<br>Nam<br>
</div>