<div dir="ltr">On Fri, Dec 28, 2012 at 11:57 PM, Richard Frank <span dir="ltr">&lt;<a href="mailto:rickfrank@me.com" target="_blank">rickfrank@me.com</a>&gt;</span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Thanks- I&#39;m doing that. Given two smart pointers allocated with ::New() macro, what should happen to the lhs on assignment?<br>

</blockquote><div><br></div><div style>If I remember correctly, this is what&#39;s happening:</div><div> </div><div><span style="color:rgb(80,0,80)">&gt;&gt; vtkSmartPointer&lt;</span><span style="color:rgb(80,0,80)">vtkVolumeRayCastCompositionFun</span><span style="color:rgb(80,0,80)">ction&gt; one = vtkVolumeRayCastCompositionFun</span><span style="color:rgb(80,0,80)">ction::New();</span><br style="color:rgb(80,0,80)">

<br>one&#39;s reference count is 2 -- once from vtkVolumeRayCastCompositionFunction::New(), and again from vtkSmartPointer::operator=().<br><br><span style="color:rgb(80,0,80)">&gt;&gt; vtkSmartPointer&lt;</span><span style="color:rgb(80,0,80)">vtkVolumeRayCastCompositionFun</span><span style="color:rgb(80,0,80)">ction&gt; two = vtkVolumeRayCastCompositionFun</span><span style="color:rgb(80,0,80)">ction::New();</span><br style="color:rgb(80,0,80)">

<br>two&#39;s reference count is also 2.<br style="color:rgb(80,0,80)"><br style="color:rgb(80,0,80)"><span style="color:rgb(80,0,80)">&gt;&gt; one = two;</span><br style="color:rgb(80,0,80)"></div><div><br></div><div style>

one should get decref&#39;d to 1, while two gets increased to 3. Since one&#39;s refcount never gets to zero, the destructor never gets called.</div><div><br></div><div style> Using the method David mentioned:</div><div style>

<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class=""><div class="h5">&gt; vtkSmartPointer&lt;vtkVolumeRayCastCompositionFunction&gt; one =<br>


&gt;  vtkSmartPointer&lt;vtkVolumeRayCastCompositionFunction&gt;::New();<br></div></div></blockquote><div> <br></div><div style>one has 1 reference. You can check this by calling GetReferenceCount on the pointers.</div><div style>

<br></div><div style>If you don&#39;t need to reassign the pointer, vtkNew is another useful smart pointer class that you may find useful. This article provides a nice short summary of these classes, and also vtkWeakPointer:</div>

<div style><br></div><div style><a href="http://www.kitware.com/source/home/post/7">http://www.kitware.com/source/home/post/7</a><br></div><div style><br></div><div style>Hope this helps,</div><div style>Dave</div></div>
</div>
</div>