<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>Ah i see, thanks. I wasn't using the smart pointer template ::New().&nbsp;<br><br>Rick Frank</div><div><br>On Jan 2, 2013, at 5:08 PM, David Lonie &lt;<a href="mailto:david.lonie@kitware.com">david.lonie@kitware.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><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'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's happening:</div><div>&nbsp;</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'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'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'd to 1, while two gets increased to 3. Since one's refcount never gets to zero, the destructor never gets called.</div><div><br></div><div style="">&nbsp;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; &nbsp;vtkSmartPointer&lt;vtkVolumeRayCastCompositionFunction&gt;::New();<br></div></div></blockquote><div>&nbsp;<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'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>
</div></blockquote></body></html>