<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'>
Hi Chasan,<br><br>You'll have to call Delete on each and every object you don't want to keep.&nbsp; The order of delete does not matter as each object is reference counted and will be actually deleted when the reference count goes to zero.<br><br>Another method is to not use vtkSmartPointer on the objects you want to batch delete.&nbsp; Say you want the Renderer to go away when the render window goes away, you would do it like this:<br><br>&nbsp;&nbsp;&nbsp; vtkRenderer* renderer = vtkRenderer::New();&nbsp;&nbsp;&nbsp; // renderer has ref count 1<br>&nbsp;&nbsp;&nbsp; vtkRenderWindow* win = vtkRendererWindow::New();<br>&nbsp;&nbsp;&nbsp; win-&gt;AddRenderer(renderer);&nbsp;&nbsp;&nbsp; // renderer has ref count 2<br>&nbsp;&nbsp;&nbsp; renderer-&gt;Delete();&nbsp;&nbsp;&nbsp; // renderer has ref count 1 from vtkRenderWindwo()<br><br>In the above example, when win is destroyed, win will remove the last ref count in renderer object, in turn causes renderer be destroyed.<br><br>Hope this helps!<br><br>Xiaofeng<br><br>P.S. Personally, I don't like to over use vtkSmartPointer<br><br><br>&gt; Date: Wed, 11 May 2011 08:26:35 +0800<br>&gt; From: pfb@exadios.com<br>&gt; To: vtkusers@vtk.org<br>&gt; Subject: Re: [vtkusers] What is the order of calling delete methods on a pipeline?<br>&gt; <br>&gt; Hi Chasan;<br>&gt; <br>&gt; I'm not clear what you want to keep. Which of the objects in the code<br>&gt; below do you need to keep?<br>&gt; <br>&gt; On Sun, 8 May 2011, chasank wrote:<br>&gt; <br>&gt; &gt; Hi Peter,<br>&gt; &gt;<br>&gt; &gt; I have designed a class containing many vtk objects, that's why I do not<br>&gt; &gt; want<br>&gt; &gt; to release memory resources by scope. The other vtk objects have to live.<br>&gt; &gt; I want to release only volume rendering pipeline on runtime. How can I do it<br>&gt; &gt; safely?<br>&gt; &gt; Thanks!<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; Peter F Bradshaw wrote:<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; Hi Chasan;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; If you wish to release the pipeline below why not encase it in its own<br>&gt; &gt; &gt; scope? If you are using vtkSmartPointer, which you are, then the<br>&gt; &gt; &gt; pipeline will be destroyed when it goes out of scope.<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; On Sat, 7 May 2011, Chasan KIOUTSOUKMOUSTAFA wrote:<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;&gt; I have a volume rendering pipeline and I want to release all the memory<br>&gt; &gt; &gt;&gt; resources of pipeline on runtime .<br>&gt; &gt; &gt;&gt; How can I release memory resources of the pipeline safely?<br>&gt; &gt; &gt;&gt; It seems the iren is the end of pipeline, if I call the iren-&gt;Delete(),<br>&gt; &gt; &gt;&gt; will<br>&gt; &gt; &gt;&gt; it delete recursively all of the pipeline?<br>&gt; &gt; &gt;&gt; What is the solution ? Pipeline is below. Thanks for answers!!<br>&gt; &gt; &gt;&gt;<br>&gt; &gt; &gt;&gt;     renderer = vtkSmartPointer &lt; vtkRenderer &gt; :: New();<br>&gt; &gt; &gt;&gt;     renderWindow = vtkSmartPointer &lt; vtkWin32OpenGLRenderWindow &gt; ::<br>&gt; &gt; &gt;&gt; New();<br>&gt; &gt; &gt;&gt;     renderWindow-&gt;AddRenderer(renderer);<br>&gt; &gt; &gt;&gt;     renderWindow-&gt;SetSize(width, height);<br>&gt; &gt; &gt;&gt;<br>&gt; &gt; &gt;&gt;     iren = vtkSmartPointer &lt; vtkWin32RenderWindowInteractor &gt; :: New();<br>&gt; &gt; &gt;&gt;     iren-&gt;SetRenderWindow(renderWindow);<br>&gt; &gt; &gt;&gt;<br>&gt; &gt; &gt;&gt;     volumeMapper =<br>&gt; &gt; &gt;&gt; vtkSmartPointer&lt;vtkFixedPointVolumeRayCastMapper&gt;::New();<br>&gt; &gt; &gt;&gt;     volumeMapper-&gt;SetInputConnection(reader-&gt;GetOutputPort());<br>&gt; &gt; &gt;&gt;     volumeMapper-&gt;SetBlendModeToComposite();<br>&gt; &gt; &gt;&gt;<br>&gt; &gt; &gt;&gt;     volumeColor = vtkSmartPointer&lt;vtkColorTransferFunction&gt;::New();<br>&gt; &gt; &gt;&gt;     volumeColor-&gt;AddRGBPoint(0,    0.0, 0.0, 0.0);<br>&gt; &gt; &gt;&gt;     volumeColor-&gt;AddRGBPoint(500,  1.0, 0.5, 0.3);<br>&gt; &gt; &gt;&gt;     volumeColor-&gt;AddRGBPoint(1000, 1.0, 0.5, 0.3);<br>&gt; &gt; &gt;&gt;     volumeColor-&gt;AddRGBPoint(1150, 1.0, 1.0, 0.9);<br>&gt; &gt; &gt;&gt;<br>&gt; &gt; &gt;&gt;     volumeScalarOpacity =  vtkSmartPointer&lt;vtkPiecewiseFunction&gt;::New();<br>&gt; &gt; &gt;&gt;     volumeScalarOpacity-&gt;AddPoint(0,    0.00);<br>&gt; &gt; &gt;&gt;     volumeScalarOpacity-&gt;AddPoint(500,  0.15);<br>&gt; &gt; &gt;&gt;     volumeScalarOpacity-&gt;AddPoint(1000, 0.15);<br>&gt; &gt; &gt;&gt;     volumeScalarOpacity-&gt;AddPoint(1150, 0.90);<br>&gt; &gt; &gt;&gt;<br>&gt; &gt; &gt;&gt;     volumeGradientOpacity = vtkSmartPointer&lt;vtkPiecewiseFunction&gt;::New();<br>&gt; &gt; &gt;&gt;     volumeGradientOpacity-&gt;AddPoint(0,   0.0);<br>&gt; &gt; &gt;&gt;     volumeGradientOpacity-&gt;AddPoint(90,  0.5);<br>&gt; &gt; &gt;&gt;     volumeGradientOpacity-&gt;AddPoint(100, 1.0);<br>&gt; &gt; &gt;&gt;<br>&gt; &gt; &gt;&gt;     volumeProperty = vtkSmartPointer&lt;vtkVolumeProperty&gt;::New();<br>&gt; &gt; &gt;&gt;     volumeProperty-&gt;SetColor(volumeColor);<br>&gt; &gt; &gt;&gt;     volumeProperty-&gt;SetScalarOpacity(volumeScalarOpacity);<br>&gt; &gt; &gt;&gt;     volumeProperty-&gt;SetGradientOpacity(volumeGradientOpacity);<br>&gt; &gt; &gt;&gt;     volumeProperty-&gt;SetInterpolationTypeToLinear();<br>&gt; &gt; &gt;&gt;     volumeProperty-&gt;ShadeOff();<br>&gt; &gt; &gt;&gt;     volumeProperty-&gt;SetAmbient(0.4);<br>&gt; &gt; &gt;&gt;     volumeProperty-&gt;SetDiffuse(0.6);<br>&gt; &gt; &gt;&gt;     volumeProperty-&gt;SetSpecular(0.2);<br>&gt; &gt; &gt;&gt;<br>&gt; &gt; &gt;&gt;     LODProperty = vtkSmartPointer &lt;vtkLODProp3D&gt;::New();<br>&gt; &gt; &gt;&gt;     int id = LODProperty-&gt;AddLOD(volumeMapper, volumeProperty, 0.0);<br>&gt; &gt; &gt;&gt;     LODProperty-&gt;SetLODLevel(id, 0.0);<br>&gt; &gt; &gt;&gt;<br>&gt; &gt; &gt;&gt;     renderer-&gt;AddViewProp(LODProperty);<br>&gt; &gt; &gt;&gt;     renderer-&gt;ResetCamera();<br>&gt; &gt; &gt;&gt;     renderer-&gt;Render();<br>&gt; &gt; &gt;&gt;<br>&gt; &gt; &gt;&gt;     iren-&gt;Initialize();<br>&gt; &gt; &gt;&gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; Cheers<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; --<br>&gt; &gt; &gt; Peter F Bradshaw: http://www.exadios.com (public keys avaliable there).<br>&gt; &gt; &gt; Personal site: http://personal.exadios.com<br>&gt; &gt; &gt; "I love truth, and the way the government still uses it occasionally to<br>&gt; &gt; &gt;  keep us guessing." - Sam Kekovich.<br>&gt; <br>&gt; Cheers<br>&gt; <br>&gt; -- <br>&gt; Peter F Bradshaw: http://www.exadios.com (public keys avaliable there).<br>&gt; Personal site: http://personal.exadios.com<br>&gt; "I love truth, and the way the government still uses it occasionally to<br>&gt;  keep us guessing." - Sam Kekovich.<br>&gt; _______________________________________________<br>&gt; Powered by www.kitware.com<br>&gt; <br>&gt; Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html<br>&gt; <br>&gt; Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ<br>&gt; <br>&gt; Follow this link to subscribe/unsubscribe:<br>&gt; http://www.vtk.org/mailman/listinfo/vtkusers<br>                                               </body>
</html>