<div dir="ltr">You shouldn&#39;t do this:<div><span class="Apple-style-span" style="border-collapse: collapse; ">&nbsp;&nbsp; &nbsp; &nbsp; vtk_extractor-&gt;SetInput(pThis-&gt;m_vtkvolumedata);<br></span><div class="gmail_quote">...after a vtk_extractor-&gt;Delete() call...</div>
<div class="gmail_quote"><br></div><div class="gmail_quote">...maybe you meant to &quot;SetInput(NULL)&quot; *before* deleting it...?</div><div class="gmail_quote"><br></div><div class="gmail_quote">Try removing that SetInput call at the bottom of your proc to see if things improve at all.</div>
<div class="gmail_quote"><br></div><div class="gmail_quote">Next, I would try eliminating the VTK objects one by one to try to isolate which one is causing the leak (if any)... If you eliminate them all and still have a leak, then look to your surrounding code. Otherwise, let us know if you find the leak in VTK code at all. If you can isolate it, we can fix it.</div>
<div class="gmail_quote"><br></div><div class="gmail_quote"><br></div><div class="gmail_quote">Thx,</div><div class="gmail_quote">David</div><div class="gmail_quote"><br></div><div class="gmail_quote"><br></div><div class="gmail_quote">
On Thu, Jul 31, 2008 at 10:37 AM, Andi2008 <span dir="ltr">&lt;<a href="mailto:mail-andi@web.de">mail-andi@web.de</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
ok, here is a vtk part of my code. I manage different vtk pipelines in<br>
different threads. an object of class CImageVtkWnd manages the different<br>
threads. I use an offscreen rendering and create screenshots of the result.<br>
I also have the leaks when use Onscreenrendering.<br>
<br>
&nbsp;This is the methode i call in one thread<br>
<br>
UINT __cdecl CImageVtkWnd::VTK3DProc(LPVOID lpParameter)<br>
{<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;CImageVtkWnd *pThis = static_cast&lt;CImageVtkWnd *&gt;(lpParameter);<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;ASSERT(pThis != NULL);<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;//build the RenderPipeline<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtkRenderer *vtk_Renderer = vtkRenderer::New();<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtkWin32OpenGLRenderWindow *vtk_Win32OpenGLWindow =<br>
vtkWin32OpenGLRenderWindow::New();<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtkWin32RenderWindowInteractor *vtk_interactor =<br>
vtkWin32RenderWindowInteractor::New();<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtk_Win32OpenGLWindow-&gt;AddRenderer(vtk_Renderer);<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtk_Win32OpenGLWindow-&gt;OffScreenRenderingOn();<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtkContourFilter *vtk_extractor = vtkContourFilter::New();<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtk_extractor-&gt;SetInput(pThis-&gt;m_vtkvolumedata); //vtkImageData from<br>
vtkImport<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtk_extractor-&gt;SetValue(0, 350);<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtk_extractor-&gt;ReleaseDataFlagOn();<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtkStripper *vtk_stripper = vtkStripper::New();<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtk_stripper-&gt;SetInputConnection(vtk_extractor-&gt;GetOutputPort());<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtkPolyDataMapper *vtk_3dmapper = vtkPolyDataMapper::New();<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtk_3dmapper-&gt;SetInputConnection(vtk_stripper-&gt;GetOutputPort());<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtk_3dmapper-&gt;ScalarVisibilityOff();<br>
<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtkActor *vtk_3dActor &nbsp; &nbsp;= vtkActor::New();<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtk_3dActor-&gt;SetMapper(vtk_3dmapper);<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtk_3dActor-&gt;GetProperty()-&gt;SetDiffuseColor(0.9, 0.9, 0.9);<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtk_Renderer-&gt;AddActor(vtk_3dActor);<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtk_Renderer-&gt;ResetCamera();<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtk_Win32OpenGLWindow-&gt;SetSize(512,512);<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtk_interactor-&gt;SetRenderWindow(vtk_Win32OpenGLWindow);<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtk_Renderer-&gt;ResetCameraClippingRange();<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtkInteractorStyleTrackballCamera *vtk_TrackBallCam =<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;vtkInteractorStyleTrackballCamera::New();<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtk_interactor-&gt;SetInteractorStyle(vtk_TrackBallCam);<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtk_interactor-&gt;Initialize();<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;CSyncObject* pWaitObjects[] = { pThis-&gt;m_hRenderEvent,<br>
pThis-&gt;m_hTerminateLoopEvent, pThis-&gt;m_hLButtonUp, pThis-&gt;m_hLButtonDown,<br>
pThis-&gt;m_hRButtonUp, pThis-&gt;m_hRButtonDown, pThis-&gt;m_hMouseMove};<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;CMultiLock MultiLock( pWaitObjects, 7L );<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;DWORD MultiLockObj = 0;<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;int *size = vtk_Win32OpenGLWindow-&gt;GetSize();<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;BITMAPINFO bmi={0};<br>
 &nbsp; &nbsp; &nbsp; &nbsp;bmi.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);<br>
 &nbsp; &nbsp; &nbsp; &nbsp;bmi.bmiHeader.biPlanes=1;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;bmi.bmiHeader.biCompression=BI_RGB;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;bmi.bmiHeader.biBitCount=24;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;bmi.bmiHeader.biWidth=size[0];<br>
 &nbsp; &nbsp; &nbsp; &nbsp;bmi.bmiHeader.biHeight=size[1];<br>
 &nbsp; &nbsp; &nbsp; &nbsp;bmi.bmiHeader.biSizeImage=size[0] * size[1] * 24;<br>
<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;unsigned char *tmpdata;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;bool recalcRect=true;<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;do<br>
 &nbsp; &nbsp; &nbsp; &nbsp;{<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(MultiLockObj == (WAIT_OBJECT_0+1))<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(MultiLockObj == (WAIT_OBJECT_0+2))<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br>
<br>
vtk_interactor-&gt;OnLButtonUp(vtk_Win32OpenGLWindow-&gt;GetWindowId(),0,pThis-&gt;m_pMouseDelta.x,pThis-&gt;m_pMouseDelta.y);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(MultiLockObj == (WAIT_OBJECT_0+3))<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br>
<br>
vtk_interactor-&gt;OnLButtonDown(vtk_Win32OpenGLWindow-&gt;GetWindowId(),0,pThis-&gt;m_pMouseDelta.x,pThis-&gt;m_pMouseDelta.y);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(MultiLockObj == (WAIT_OBJECT_0+4))<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br>
<br>
vtk_interactor-&gt;OnRButtonUp(vtk_Win32OpenGLWindow-&gt;GetWindowId(),0,pThis-&gt;m_pMouseDelta.x,pThis-&gt;m_pMouseDelta.y);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(MultiLockObj == (WAIT_OBJECT_0+5))<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br>
<br>
vtk_interactor-&gt;OnRButtonDown(vtk_Win32OpenGLWindow-&gt;GetWindowId(),0,pThis-&gt;m_pMouseDelta.x,pThis-&gt;m_pMouseDelta.y);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(MultiLockObj == (WAIT_OBJECT_0+6))<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br>
<br>
vtk_interactor-&gt;OnMouseMove(vtk_Win32OpenGLWindow-&gt;GetWindowId(),0,pThis-&gt;m_pMouseDelta.x,pThis-&gt;m_pMouseDelta.y);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
<br>
<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;vtk_Win32OpenGLWindow-&gt;Render();<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;::EnterCriticalSection(&amp;pThis-&gt;m_cs);<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tmpdata = vtk_Win32OpenGLWindow-&gt;GetPixelData(0,0,size[0]-1,size[1]-1,1);<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pThis-&gt;m_lbitmap-&gt;ConvertFromDIB(&amp;bmi,(L_UCHAR *)tmpdata);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pThis-&gt;m_lbitmap-&gt;SetXResolution(pThis-&gt;m_iSource_resolution);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pThis-&gt;m_lbitmap-&gt;SetYResolution(pThis-&gt;m_iSource_resolution);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pThis-&gt;m_lbitmap-&gt;CalculateXYRes();<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LeaveCriticalSection(&amp;pThis-&gt;m_cs);<br>
<br>
<br>
::PostMessage(pThis-&gt;m_cParent-&gt;GetSafeHwnd(),WM_VTK_UPDATE_WINDOW,0,NULL);<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;delete tmpdata;<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;recalcRect=false;<br>
<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MultiLockObj = MultiLock.Lock( INFINITE, FALSE );<br>
 &nbsp; &nbsp; &nbsp; &nbsp;}<br>
 &nbsp; &nbsp; &nbsp; &nbsp;while(1) ;<br>
<br>
<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;//Cleanup<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtk_extractor-&gt;Delete();<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtk_stripper-&gt;Delete();<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtk_3dmapper-&gt;Delete();<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtk_3dActor-&gt;Delete();<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtk_Renderer-&gt;Delete();<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtk_Win32OpenGLWindow-&gt;Finalize();<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtk_Win32OpenGLWindow-&gt;Delete();<br>
<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtk_TrackBallCam-&gt;Delete();<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtk_interactor-&gt;Delete();<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;vtk_extractor-&gt;SetInput(pThis-&gt;m_vtkvolumedata);<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;::AfxEndThread( 0, true );<br>
 &nbsp; &nbsp; &nbsp; &nbsp;return 0L;<br>
}<br>
<br>
<br>
Greetings<br>
Andi<br>
<div><div></div><div class="Wj3C7c"><br>
<br>
<br>
<br>
David Cole wrote:<br>
&gt;<br>
&gt; Send a code snippet that demonstrates the leak you are talking about.<br>
&gt; Sounds<br>
&gt; like there is a leak internal to a class that does not get cleaned up even<br>
&gt; though its containing object does get properly cleaned up....<br>
&gt;<br>
&gt; Thx,<br>
&gt; David<br>
&gt;<br>
&gt;<br>
&gt; On Thu, Jul 31, 2008 at 10:11 AM, Andreas Brüning &lt;<a href="mailto:mail-andi@web.de">mail-andi@web.de</a>&gt;<br>
&gt; wrote:<br>
&gt;<br>
&gt;&gt; Hi everyone,<br>
&gt;&gt;<br>
&gt;&gt; i need help to clean up my application. I visualize some medical data and<br>
&gt;&gt; i<br>
&gt;&gt; am using C++,MFC and VS2005. My vtk version is a nightly version from<br>
&gt;&gt; around<br>
&gt;&gt; a week ago. By the way, regarding to my post on July/29, i solved the<br>
&gt;&gt; problem with memory leaks without creating any vtk objects by loading all<br>
&gt;&gt; vtk dll delayed. (strange MFC behavoir )<br>
&gt;&gt;<br>
&gt;&gt; My new problem is that i canŽt clean up my created vtk objects properly.<br>
&gt;&gt; I<br>
&gt;&gt; call the Delete method for all my vtk objects and when i debug my code<br>
&gt;&gt; all<br>
&gt;&gt; vtk objects are deleted, but the memory isnŽt completely freed. If i<br>
&gt;&gt; handle<br>
&gt;&gt; bigger datasets it leaks more. I also checked twice if forget to call a<br>
&gt;&gt; Delete method a vtk object ;-)<br>
&gt;&gt;<br>
&gt;&gt; Even if i create a object like maybe vtkImport (because it seems to be a<br>
&gt;&gt; quite big object) and call the Delete method immediately after it, the<br>
&gt;&gt; object is deleted but the memory isnŽt freed.<br>
&gt;&gt;<br>
&gt;&gt; I googled already half a day and i don&#39;t want to restart my programm all<br>
&gt;&gt; the time if i visualize another dataset. Did anybody had the same thing<br>
&gt;&gt; or<br>
&gt;&gt; know want can be wrong? I think it could be another wrong project<br>
&gt;&gt; property<br>
&gt;&gt; setting or maybe i use CMake with wrong settings.<br>
&gt;&gt;<br>
&gt;&gt; I could really need help. Thank in advance<br>
&gt;&gt; Andi<br>
&gt;<br>
&gt;&gt; _______________________________________________<br>
</div></div><div class="Ih2E3d">&gt;&gt; This is the private VTK discussion list.<br>
&gt;&gt; Please keep messages on-topic. Check the FAQ at:<br>
&gt;&gt; <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
&gt;&gt; Follow this link to subscribe/unsubscribe:<br>
&gt;&gt; <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
&gt;&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; This is the private VTK discussion list.<br>
&gt; Please keep messages on-topic. Check the FAQ at:<br>
&gt; <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
&gt; Follow this link to subscribe/unsubscribe:<br>
&gt; <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
&gt;<br>
&gt;<br>
<br>
</div><font color="#888888">--<br>
View this message in context: <a href="http://www.nabble.com/Delete-vtkobjects-properly-in-MFC-tp18755524p18756045.html" target="_blank">http://www.nabble.com/Delete-vtkobjects-properly-in-MFC-tp18755524p18756045.html</a><br>

Sent from the VTK - Users mailing list archive at Nabble.com.<br>
</font><div><div></div><div class="Wj3C7c"><br>
_______________________________________________<br>
This is the private VTK discussion list.<br>
Please keep messages on-topic. Check the FAQ at: <a 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 href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
</div></div></blockquote></div><br></div></div>