Hello,<br><br>This is what I do:<br>1) Make sure there is a Delete() for each New() around each temporary (local) use.<br><br>void myfunction()<br>
{<br> vtkSomething *something = vtkSomething::New(); //ref count starts as 1<br>
//do some things here<br>
something->Delete(); //ref count -- = 0 which will call something'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> MyClass()<br> {<br> this->MySomething = NULL;<br> } <br> ~MyClass()<br> {<br> if (this->MySomething != NULL)<br> {<br> this->MySomething->Delete();<br> }<br> }<br><br> void MyFunction()
<br> {<br> if (this->MySomething != NULL) //Delete what I might have made before<br> {<br> this->MySomething->Delete();<br> }<br> this->MySomething = vtkSomething::New();//Create a new thing it starts with ref count 1
<br><br> //now you can use it and not call Delete(), because the destructor will eventually<br> for (int i = 0; i < 99; i++)<br> {<br> this->MySomething->CallAMethod();<br> ...<br> this->UseIt();
<br> ...<br> }<br> }<br><br> void UseIt()<br> {<br> if (this->MySomething) //sanity check<br> {<br> this->MySomething->DoSomething();<br> }<br> }<br>
}<br><br>3) If I need to pass a reference to another object I register it.<br>MyClass::PassItOff(AnotherClass *other)<br>{<br> if (this->MySomething)<br> {<br> other->HisCopy == this->MySomething();<br>
this->MySomething->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> }<br>}<br><br>Note:<br>For subclasses of vtkObject you don'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'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()'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> <<a href="mailto:burlen@apollo.sr.unh.edu">burlen@apollo.sr.unh.edu</a>> 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'm trying to make the triangulation of a point cloud using<br>vtkDelaunay2D. What I don't know is when to exactly delete filters and other<br>objects such as PolyDatas that aren't used anymore. I'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>