<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'><div dir='ltr'>
&gt;I've been using vtkImageData::New(), followed by vtkImageData-&gt;DeepCopy(filter-&gt;GetOutput()). &nbsp;I've been doing this cause I notice that once I delete the filter the output no longer exists.<BR><div>
<div>&nbsp;</div><div>Don't deep copy the image, instead do:</div><div>&nbsp;</div><div>&nbsp;&nbsp;&nbsp; vtkImageData* filterOutput = filter-&gt;GetOutput();</div><div>&nbsp;&nbsp;&nbsp; filterOutput-&gt;Register(0);&nbsp;&nbsp;&nbsp; // increment the ref count</div><div>&nbsp;</div><div>to keep the output in the memory.</div><div>&nbsp;</div><div>Just make sure you pair off every New() or Register() with a Delete().</div><div>&nbsp;</div><div>BTW, I'm not for or against the use of smart pointer for any fundamental reason.&nbsp; If one knows very well how a smart pointer class works,&nbsp;using the&nbsp;smart pointer&nbsp;to&nbsp;left the burden of tracking memory allocation can be very helpful.&nbsp; When I do decided to use smart pointer, I use it exclusively, much like in Java where every variable is a managed smart pointer.&nbsp; Mixing the usage of smart pointers and naked pointers is where trouble comes in.</div><div>&nbsp;</div><div>HTH</div><div><br><div class="ecxgmail_quote">On Tue, Sep 6, 2011 at 11:55 AM, David Gobbi <span dir="ltr">&lt;<a href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>&gt;</span> wrote:<br>
<blockquote style="padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;" class="ecxgmail_quote"><div class="ecxim"><div>On Tue, Sep 6, 2011 at 12:34 PM, Jonathan Morra <span dir="ltr">&lt;<a href="mailto:jonmorra@gmail.com">jonmorra@gmail.com</a>&gt;</span> wrote:<br>
<div class="ecxgmail_quote"><blockquote style="padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;" class="ecxgmail_quote">

This could make sense, I'm going to try and change all my method signatures to pass around const references to vtkSmartPointers where appropriate. &nbsp;Do you know what happens to the reference count upon returning a vtkSmartPointer?</blockquote>


</div><br></div><div><br></div></div><div>In VTK, smart pointers should only be used to store references, not to pass them.&nbsp;&nbsp;VTK methods should take regular pointers as arguments.</div><div><br></div><div>The general rules are:</div>


<div><br></div><div>1) Refcounts are not automatically incremented when objects are returned, i.e. when an object is returned to you, then you are just "borrowing" it. &nbsp;If you need to own it for a while, then store it in a smart pointer.</div>


<div><br></div><div>2) Refcounts are not automatically incremented when objects are passed to a method. &nbsp;If a method needs to own the object for a while, it should store it in a smart pointer. &nbsp;All methods in the VTK libraries that need to own the objects that are passed to them will increment the refcount of those objects, either by storing it in a smart pointer or by calling Register() on it.</div>


<div><br></div><div>There are a few very rare exceptions to rule #1, such as the NewInstance() method.</div><div><br></div><font color="#888888"><div>&nbsp;- David</div>
</font></blockquote></div><br></div></div>                                               </div></body>
</html>