<div dir="ltr">You shouldn't do this:<div><span class="Apple-style-span" style="border-collapse: collapse; "> vtk_extractor->SetInput(pThis->m_vtkvolumedata);<br></span><div class="gmail_quote">...after a vtk_extractor->Delete() call...</div>
<div class="gmail_quote"><br></div><div class="gmail_quote">...maybe you meant to "SetInput(NULL)" *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"><<a href="mailto:mail-andi@web.de">mail-andi@web.de</a>></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>
This is the methode i call in one thread<br>
<br>
UINT __cdecl CImageVtkWnd::VTK3DProc(LPVOID lpParameter)<br>
{<br>
<br>
<br>
CImageVtkWnd *pThis = static_cast<CImageVtkWnd *>(lpParameter);<br>
<br>
ASSERT(pThis != NULL);<br>
<br>
//build the RenderPipeline<br>
<br>
vtkRenderer *vtk_Renderer = vtkRenderer::New();<br>
vtkWin32OpenGLRenderWindow *vtk_Win32OpenGLWindow =<br>
vtkWin32OpenGLRenderWindow::New();<br>
vtkWin32RenderWindowInteractor *vtk_interactor =<br>
vtkWin32RenderWindowInteractor::New();<br>
<br>
<br>
vtk_Win32OpenGLWindow->AddRenderer(vtk_Renderer);<br>
vtk_Win32OpenGLWindow->OffScreenRenderingOn();<br>
<br>
<br>
vtkContourFilter *vtk_extractor = vtkContourFilter::New();<br>
<br>
<br>
vtk_extractor->SetInput(pThis->m_vtkvolumedata); //vtkImageData from<br>
vtkImport<br>
vtk_extractor->SetValue(0, 350);<br>
vtk_extractor->ReleaseDataFlagOn();<br>
<br>
<br>
vtkStripper *vtk_stripper = vtkStripper::New();<br>
vtk_stripper->SetInputConnection(vtk_extractor->GetOutputPort());<br>
<br>
<br>
vtkPolyDataMapper *vtk_3dmapper = vtkPolyDataMapper::New();<br>
vtk_3dmapper->SetInputConnection(vtk_stripper->GetOutputPort());<br>
vtk_3dmapper->ScalarVisibilityOff();<br>
<br>
<br>
<br>
vtkActor *vtk_3dActor = vtkActor::New();<br>
<br>
vtk_3dActor->SetMapper(vtk_3dmapper);<br>
vtk_3dActor->GetProperty()->SetDiffuseColor(0.9, 0.9, 0.9);<br>
<br>
vtk_Renderer->AddActor(vtk_3dActor);<br>
vtk_Renderer->ResetCamera();<br>
<br>
<br>
vtk_Win32OpenGLWindow->SetSize(512,512);<br>
vtk_interactor->SetRenderWindow(vtk_Win32OpenGLWindow);<br>
<br>
vtk_Renderer->ResetCameraClippingRange();<br>
<br>
<br>
vtkInteractorStyleTrackballCamera *vtk_TrackBallCam =<br>
vtkInteractorStyleTrackballCamera::New();<br>
<br>
vtk_interactor->SetInteractorStyle(vtk_TrackBallCam);<br>
vtk_interactor->Initialize();<br>
<br>
CSyncObject* pWaitObjects[] = { pThis->m_hRenderEvent,<br>
pThis->m_hTerminateLoopEvent, pThis->m_hLButtonUp, pThis->m_hLButtonDown,<br>
pThis->m_hRButtonUp, pThis->m_hRButtonDown, pThis->m_hMouseMove};<br>
<br>
CMultiLock MultiLock( pWaitObjects, 7L );<br>
<br>
<br>
DWORD MultiLockObj = 0;<br>
<br>
int *size = vtk_Win32OpenGLWindow->GetSize();<br>
<br>
<br>
BITMAPINFO bmi={0};<br>
bmi.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);<br>
bmi.bmiHeader.biPlanes=1;<br>
bmi.bmiHeader.biCompression=BI_RGB;<br>
bmi.bmiHeader.biBitCount=24;<br>
bmi.bmiHeader.biWidth=size[0];<br>
bmi.bmiHeader.biHeight=size[1];<br>
bmi.bmiHeader.biSizeImage=size[0] * size[1] * 24;<br>
<br>
<br>
<br>
unsigned char *tmpdata;<br>
bool recalcRect=true;<br>
<br>
do<br>
{<br>
if(MultiLockObj == (WAIT_OBJECT_0+1))<br>
{<br>
break;<br>
}<br>
<br>
if(MultiLockObj == (WAIT_OBJECT_0+2))<br>
{<br>
<br>
vtk_interactor->OnLButtonUp(vtk_Win32OpenGLWindow->GetWindowId(),0,pThis->m_pMouseDelta.x,pThis->m_pMouseDelta.y);<br>
}<br>
<br>
<br>
if(MultiLockObj == (WAIT_OBJECT_0+3))<br>
{<br>
<br>
vtk_interactor->OnLButtonDown(vtk_Win32OpenGLWindow->GetWindowId(),0,pThis->m_pMouseDelta.x,pThis->m_pMouseDelta.y);<br>
}<br>
<br>
if(MultiLockObj == (WAIT_OBJECT_0+4))<br>
{<br>
<br>
vtk_interactor->OnRButtonUp(vtk_Win32OpenGLWindow->GetWindowId(),0,pThis->m_pMouseDelta.x,pThis->m_pMouseDelta.y);<br>
}<br>
if(MultiLockObj == (WAIT_OBJECT_0+5))<br>
{<br>
<br>
vtk_interactor->OnRButtonDown(vtk_Win32OpenGLWindow->GetWindowId(),0,pThis->m_pMouseDelta.x,pThis->m_pMouseDelta.y);<br>
}<br>
<br>
if(MultiLockObj == (WAIT_OBJECT_0+6))<br>
{<br>
<br>
vtk_interactor->OnMouseMove(vtk_Win32OpenGLWindow->GetWindowId(),0,pThis->m_pMouseDelta.x,pThis->m_pMouseDelta.y);<br>
}<br>
<br>
<br>
<br>
<br>
vtk_Win32OpenGLWindow->Render();<br>
<br>
::EnterCriticalSection(&pThis->m_cs);<br>
<br>
tmpdata = vtk_Win32OpenGLWindow->GetPixelData(0,0,size[0]-1,size[1]-1,1);<br>
<br>
<br>
pThis->m_lbitmap->ConvertFromDIB(&bmi,(L_UCHAR *)tmpdata);<br>
pThis->m_lbitmap->SetXResolution(pThis->m_iSource_resolution);<br>
pThis->m_lbitmap->SetYResolution(pThis->m_iSource_resolution);<br>
pThis->m_lbitmap->CalculateXYRes();<br>
<br>
LeaveCriticalSection(&pThis->m_cs);<br>
<br>
<br>
::PostMessage(pThis->m_cParent->GetSafeHwnd(),WM_VTK_UPDATE_WINDOW,0,NULL);<br>
<br>
<br>
delete tmpdata;<br>
<br>
recalcRect=false;<br>
<br>
<br>
<br>
MultiLockObj = MultiLock.Lock( INFINITE, FALSE );<br>
}<br>
while(1) ;<br>
<br>
<br>
<br>
<br>
//Cleanup<br>
<br>
vtk_extractor->Delete();<br>
vtk_stripper->Delete();<br>
vtk_3dmapper->Delete();<br>
vtk_3dActor->Delete();<br>
<br>
<br>
vtk_Renderer->Delete();<br>
vtk_Win32OpenGLWindow->Finalize();<br>
vtk_Win32OpenGLWindow->Delete();<br>
<br>
<br>
<br>
vtk_TrackBallCam->Delete();<br>
vtk_interactor->Delete();<br>
<br>
vtk_extractor->SetInput(pThis->m_vtkvolumedata);<br>
<br>
::AfxEndThread( 0, true );<br>
return 0L;<br>
}<br>
<br>
<br>
Greetings<br>
Andi<br>
<div><div></div><div class="Wj3C7c"><br>
<br>
<br>
<br>
David Cole wrote:<br>
><br>
> Send a code snippet that demonstrates the leak you are talking about.<br>
> Sounds<br>
> like there is a leak internal to a class that does not get cleaned up even<br>
> though its containing object does get properly cleaned up....<br>
><br>
> Thx,<br>
> David<br>
><br>
><br>
> On Thu, Jul 31, 2008 at 10:11 AM, Andreas Brüning <<a href="mailto:mail-andi@web.de">mail-andi@web.de</a>><br>
> wrote:<br>
><br>
>> Hi everyone,<br>
>><br>
>> i need help to clean up my application. I visualize some medical data and<br>
>> i<br>
>> am using C++,MFC and VS2005. My vtk version is a nightly version from<br>
>> around<br>
>> a week ago. By the way, regarding to my post on July/29, i solved the<br>
>> problem with memory leaks without creating any vtk objects by loading all<br>
>> vtk dll delayed. (strange MFC behavoir )<br>
>><br>
>> My new problem is that i canŽt clean up my created vtk objects properly.<br>
>> I<br>
>> call the Delete method for all my vtk objects and when i debug my code<br>
>> all<br>
>> vtk objects are deleted, but the memory isnŽt completely freed. If i<br>
>> handle<br>
>> bigger datasets it leaks more. I also checked twice if forget to call a<br>
>> Delete method a vtk object ;-)<br>
>><br>
>> Even if i create a object like maybe vtkImport (because it seems to be a<br>
>> quite big object) and call the Delete method immediately after it, the<br>
>> object is deleted but the memory isnŽt freed.<br>
>><br>
>> I googled already half a day and i don't want to restart my programm all<br>
>> the time if i visualize another dataset. Did anybody had the same thing<br>
>> or<br>
>> know want can be wrong? I think it could be another wrong project<br>
>> property<br>
>> setting or maybe i use CMake with wrong settings.<br>
>><br>
>> I could really need help. Thank in advance<br>
>> Andi<br>
><br>
>> _______________________________________________<br>
</div></div><div class="Ih2E3d">>> This is the private VTK discussion list.<br>
>> Please keep messages on-topic. Check the FAQ at:<br>
>> <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>
>><br>
><br>
> _______________________________________________<br>
> This is the private VTK discussion list.<br>
> Please keep messages on-topic. Check the FAQ at:<br>
> <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>
><br>
><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>