<div dir="ltr">On Fri, Dec 28, 2012 at 11:57 PM, Richard Frank <span dir="ltr"><<a href="mailto:rickfrank@me.com" target="_blank">rickfrank@me.com</a>></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> </div><div><span style="color:rgb(80,0,80)">>> vtkSmartPointer<</span><span style="color:rgb(80,0,80)">vtkVolumeRayCastCompositionFun</span><span style="color:rgb(80,0,80)">ction> 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)">>> vtkSmartPointer<</span><span style="color:rgb(80,0,80)">vtkVolumeRayCastCompositionFun</span><span style="color:rgb(80,0,80)">ction> 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)">>> 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> 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">> vtkSmartPointer<vtkVolumeRayCastCompositionFunction> one =<br>
> vtkSmartPointer<vtkVolumeRayCastCompositionFunction>::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'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>