At first glance, I do not see anything obviously incorrect about your code.<br><br>Have you tried similar code using Kitware&#39;s ActiViz .NET Personal Edition?<br><br>We run test suites that do similar tasks and do not see memory leaks like this in our testing for ActiViz (we have leak checking built in to VTK, and we have seen leak reports when there have been bugs in the past...)<br>
<div class="gmail_quote"><br>I am not familiar with the implementation of the vtkdotnet C# wrappers, but if you see similar behavior with ActiViz .NET, I&#39;d be interested to hear about that...<br><br><br>HTH,<br>David Cole<br>
Kitware, Inc.<br><br><br>On Fri, May 8, 2009 at 4:00 PM, Theodore Holden <span dir="ltr">&lt;<a href="mailto:theodoreholden@yahoo.com">theodoreholden@yahoo.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><div>If I can solve one or two more problems here, I&#39;ll be looking at replacing an existing system of around 12,000 lines of OpenGL code with a couple of hundred lines of VTK code, and the VTK graphics look better.  It&#39;s probably a common situation, the data involved is fairly simple but the existing code for presenting it is byzantine and borderline unmaintainable.  <br>
<br><span>But there&#39;s a big and non-obvious problem with a memory leak in the picture.  The application reads data from a proprietary file, writes that data out to a .vtk file, and then calls a function which uses VTK code to draw the data on a VTK form which is created using the sourceforge wrapper library and component for c# available at <a href="http://vtkdotnet.sourceforge.net/" target="_blank">http://vtkdotnet.sourceforge.net/</a>.</span><br>
<br>The problem I&#39;m seeing is definitely in the VTK code and not any part of the code which generates the data.  If I insert a return statement just prior to the call to the vtk code, the memory leak vanishes.<br><br>
Worse, the Red-Gate ANTS memory profiler offers no help;  it shows the largest objects in the system being a couple of inconsequential byte arrays which are definitely not part of the problem.<br><br>The examples provided show functions with names like AddConeSurfaceToWindow and AddFlamingoToWindow.<br>
<br>Trying to use the same techniques produces a function which looks like this:<br><br><div style="margin-left: 80px; color: rgb(0, 128, 255);"><font size="1">       // 3d texture<br>        void AddBagVolumeToWindow4(vtk.vtkRenderWindow
 renWin)<br>        {<br>            // 3d texture map<br>            vtkStructuredPointsReader reader = new vtkStructuredPointsReader();<br>            vtkVolume volume = new vtkVolume();<br>            vtkVolumeProperty volumeProperty = new vtkVolumeProperty();            <br>
            vtkRenderer renderer = new vtkRenderer();<br>            vtkRenderWindowInteractor interactor = new vtkRenderWindowInteractor();<br>            vtkVolumeTextureMapper3D volumeMapper = new
 vtkVolumeTextureMapper3D();<br>            vtkPiecewiseFunction opacity = new vtkPiecewiseFunction();<br>            vtkColorTransferFunction color = new vtkColorTransferFunction();<br><br>            reader.SetFileName(&quot;c:\\zz.vtk&quot;);<br>
            reader.Update();<br>            ifileLoaded = 1;  <br><br>            opacity.AddPoint(0, 0);<br>            opacity.AddPoint(64, .005);<br>            opacity.AddPoint(127, .01);<br>            opacity.AddPoint(128,
 .05);<br>            opacity.AddPoint(200, .5);<br><br>            color.AddRGBPoint(0, 1, 1, 1);<br>            color.AddRGBPoint(126, .665, .84, .88);<br>            color.AddRGBPoint(127, 0, 1, 0);<br>            color.AddRGBPoint(199, 1, 0, 0);<br>
<br>            volumeProperty.SetColor(color);<br>            volumeProperty.SetScalarOpacity(opacity);<br>            volumeProperty.SetInterpolationTypeToLinear();<br>           
 volumeProperty.ShadeOn();<br><br>            volumeMapper.SetInput(reader.GetOutput());<br><br>            volume.SetMapper(volumeMapper);<br>            volume.SetProperty(volumeProperty);<br><br>            renderer.SetBackground(1, 1, 1);<br>
            renderer.AddVolume(volume);<br>            interactor.SetRenderWindow(renWin);           <br><br>            renWin.AddRenderer(renderer);<br><br>           
 renWin.Render();<br>            interactor.Start();<br><br>            reader.Dispose();<br>            volume.Dispose();<br>            volumeProperty.Dispose();<br>            renderer.Dispose();<br>            interactor.Dispose();<br>
            opacity.Dispose();<br>            color.Dispose();<br><br>            vtk.vtkWin32OpenGLRenderWindow win32win =<br>               
 vtk.vtkWin32OpenGLRenderWindow.SafeDownCast(renWin);<br>            win32win.Clean();<br>        }<br></font></div><br>Again testing indicates that the memory leak has nothing to do with code outside of this function and a memory profiler reputed to be the best provides no information.  I get the impression that many if not most VTK apps only need to put a particular 3D image on a screen once, while this function is called repeatedly as a succession of images is read in by the user.  Again the read process reads data and throws it out to c:\\zz.vtk, which the vtk code then reads.<br>
<br>It occurred to me that eliminating the repeated VTK constructor calls might help.  That leads to this code in the app constructor:<br><br><div style="margin-left: 80px; color: rgb(0, 128, 255);"><font size="1">       public
 Form1()<br>        {  <br>            InitializeComponent();<br><br>            // clear out vtk widget screen<br>            vtkForm1.GetRenderWindow().Frame();<br>            vtkRenderer vr = new vtkRenderer();<br>            vr.SetBackground(1, 1, 1);<br>
            vr.SetRenderWindow(vtkForm1.GetRenderWindow());<br>            vtkForm1.GetRenderWindow().AddRenderer(vr);<br>            vr.Clear();<br>           
 vr.Render();<br>            vtk.vtkWin32OpenGLRenderWindow win32win =<br>                vtk.vtkWin32OpenGLRenderWindow.SafeDownCast(vtkForm1.GetRenderWindow());<br>            win32win.Clean();<br><br>            // set viewing objects for 3D texture map model           <br>
            volume4 = new vtkVolume();<br>            volumeProperty4 = new vtkVolumeProperty();<br>            renderer4 = new vtkRenderer();<br>            interactor4 = new
 vtkRenderWindowInteractor();<br>            volumeMapper4 = new vtkVolumeTextureMapper3D();    <br><br>            opacity = new vtkPiecewiseFunction();<br>            color   = new vtkColorTransferFunction();<br>            <br>
            renderer4.AddVolume(volume4);            <br>            vtkForm1.GetRenderWindow().AddRenderer(renderer4);<br>            volume4.SetMapper(volumeMapper4);<br>           
 volume4.SetProperty(volumeProperty4);   <br>        }<br></font></div><br>and then a modified function to display images:<br><br><div style="margin-left: 80px; color: rgb(0, 128, 255);"><font size="1">        void AddBagVolumeToWindow4(vtk.vtkRenderWindow renWin)<br>
        {<br>            <br>            vtkStructuredPointsReader reader4 = new vtkStructuredPointsReader();<br>            reader4.SetFileName(&quot;c:\\zz.vtk&quot;);<br>            reader4.Update();<br><br>            opacity.AddPoint(0, 0);<br>
           
 opacity.AddPoint(64, .005);<br>            opacity.AddPoint(128, .01);<br>            opacity.AddPoint(200, .05);<br>            opacity.AddPoint(220, .4);<br><br>            color.AddRGBPoint(64, .665, .84, .88);<br>            color.AddRGBPoint(128, 0, .746, .95);<br>
            color.AddRGBPoint(220, 0, 1, 0);<br>            color.AddRGBPoint(230, 1, 0, 0);<br><br>            volumeProperty4.SetColor(color);<br>           
 volumeProperty4.SetScalarOpacity(opacity);<br>            volumeProperty4.SetInterpolationTypeToLinear();<br>            volumeProperty4.ShadeOn();<br><br>            volumeMapper4.SetInput(reader4.GetOutput());<br>            volumeMapper4.Update();<br>
<br>            renderer4.SetBackground(1, 1, 1);          <br>            interactor4.SetRenderWindow(renWin);  <br>           <br>           
 renWin.Render();<br>            interactor4.Start();<br><br>            reader4.Dispose();<br>            GC.Collect();<br>            <br>            vtk.vtkWin32OpenGLRenderWindow win32win =<br>                vtk.vtkWin32OpenGLRenderWindow.SafeDownCast(renWin);<br>
            win32win.Clean();   <br>            <br>        }<br></font></div><br>But even that doesn&#39;t help.  The computer loses around 50MB each time a new image is read in and these
 images are not that large, more like around 10MB on average.  <br><br>Again I&#39;m new at this, and any help or information would be appreciated.<br><br><br>Ted<br><br><br><br><br><br><br><br><br><br><br><br><br><br></div>
</div><br>

      </div><br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
<br></blockquote></div><br>