Hello,<br><br>This is what I do:<br>1)&nbsp; Make sure there is a Delete() for each New() around each temporary (local) use.<br><br>void myfunction()<br>
{<br>&nbsp; vtkSomething *something = vtkSomething::New(); //ref count starts as 1<br>
&nbsp; //do some things here<br>
&nbsp; something-&gt;Delete(); //ref count -- = 0 which will call something&#39;s destructor to and deallocate it<br>
}<br>
<br>2) When I want to keep the object around and use it later, I save it in an ivar within a class, and destroy it in the classes destructor, or whenever the instance of the object is replaced with another one.<br><br>class MyClass {
<br>&nbsp; MyClass()<br>&nbsp; {<br>&nbsp;&nbsp;&nbsp; this-&gt;MySomething = NULL;<br>&nbsp; } <br>&nbsp; ~MyClass()<br>&nbsp; {<br>&nbsp;&nbsp;&nbsp; if (this-&gt;MySomething != NULL)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this-&gt;MySomething-&gt;Delete();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp; }<br><br>&nbsp; void MyFunction()
<br>&nbsp; {<br>&nbsp;&nbsp; if (this-&gt;MySomething != NULL) //Delete what I might have made before<br>&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this-&gt;MySomething-&gt;Delete();<br>&nbsp;&nbsp; }<br>&nbsp;&nbsp; this-&gt;MySomething = vtkSomething::New();//Create a new thing it starts with ref count 1
<br><br>&nbsp;&nbsp; //now you can use it and not call Delete(), because the destructor will eventually<br>&nbsp;&nbsp; for (int i = 0; i &lt; 99; i++)<br>&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this-&gt;MySomething-&gt;CallAMethod();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this-&gt;UseIt();
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...<br>&nbsp;&nbsp; }<br>&nbsp; }<br><br>&nbsp; void UseIt()<br>&nbsp; {<br>&nbsp;&nbsp;&nbsp; if (this-&gt;MySomething) //sanity check<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this-&gt;MySomething-&gt;DoSomething();<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp; }<br>
}<br><br>3) If I need to pass a reference to another object I register it.<br>MyClass::PassItOff(AnotherClass *other)<br>{<br>&nbsp;&nbsp; if (this-&gt;MySomething)<br>&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; other-&gt;HisCopy == this-&gt;MySomething();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this-&gt;MySomething-&gt;Register(); //ref count goes to 2, so now it will only be freed when this, and other Delete() it to make ref count 0<br>&nbsp;&nbsp; }<br>}<br><br>Note:<br>For subclasses of vtkObject you don&#39;t have to go through the steps of checking the old pointer, saving the new pointer and incrementing the reference count manually, you can just use the vtkSetObject Macro in VTK/Common/vtkSetGet.h
<br>So <br><br>Also note: to test if you&#39;ve got it right, turn on the VTK_DEBUG_LEAKS flag in cmake. When on, the program will check for any vtkObjects that have not been Delete()&#39;d thoroughly as it ends and print them.
<br><br>hth,<br>Dave DeMarle<br><br><br><br><div><span class="gmail_quote">On 5/21/07, <b class="gmail_sendername">burlen</b> &lt;<a href="mailto:burlen@apollo.sr.unh.edu">burlen@apollo.sr.unh.edu</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">



  
  

<div bgcolor="#ffffff" text="#000000">
Hi,<br>
Here is what I do, <br>
<br>
1) when ever you ::New() something you also Delete() it.<br>
<br>
2a) When ever you need to keep the output of a filter longer than the
filter itself call Register(0) on the output then Delete() the filter.
Make sure you Delete() the output later.<br>
<br>
2b) alternatively you could DeepCopy the output of filters you want to
keep around.<br><span class="sg">
<br>
Burlen</span><span class="q"><br>
<br>
<br>
Godofredo wrote:
<blockquote cite="http://mid10715919.post@talk.nabble.com" type="cite">
  <pre>Hi everyone. I&#39;m trying to make the triangulation of a point cloud using<br>vtkDelaunay2D. What I don&#39;t know is when to exactly delete filters and other<br>objects such as PolyDatas that aren&#39;t used anymore. I&#39;ve made some tries but
<br>with bad results. For example, if I use vtkDelaunay2D, update it and then<br>save its output in a vtkPolyData, can I delete the vtkDelaunay2D filter?<br>Many thanks. <br>  </pre>
</blockquote>
<br>
<div>-- <br>
<img border="0"></div>
</span></div>

<br>_______________________________________________<br>This is the private VTK discussion list.<br>Please keep messages on-topic. Check the FAQ at: <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">
http://www.vtk.org/Wiki/VTK_FAQ</a><br>Follow this link to subscribe/unsubscribe:<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers
</a><br><br><br clear="all"></blockquote></div><br>