[vtkusers] vtkWin32OpenGL memory leak?

Anders Vestbo anders at fmri.no
Thu Jun 9 06:37:51 EDT 2005


Dear vtk-users,

I am using vtk within a BCB application using the package 
vtkBorlandRenderWindowPkg supplied in \Examples\GUI\Win32\vtkBorland. I 
have a vtkBorlandRenderWindow placed on a TForm which is created during 
runtime by the application. When the form is created the following code 
is run (as suggested in the example code provided with the package):

void __fastcall TDTIViewer::FormCreate(TObject *Sender)
{
    // These calls are made to enforce creation of the internal
   // vtk components of the vtkBorlandRenderWindow.  If this were
   // not done, clicking on the component would attempt to pass
   // window messages to non-existent entities.

   vtkRenderWindowInteractor * iact = vtkRenderWindow1->GetInteractor();
   vtkRenderer* ren1 = vtkRenderWindow1->GetRenderer();
}
(vtkRenderWindow1 being the instance of vtkBorlandRenderWindow)

and consequently when the form is destroyed, the following eventhandler 
is called:

void __fastcall TDTIViewer::FormDestroy(TObject *Sender)
{
   delete vtkRenderWindow1;
}
(See end of mail for the corresponding code in vtkBorlandRenderWindow).

Now; when I create a instance of the form (without creating any actors; 
simply calling the FormCreate function) my task manager tells me that 
memory consumption goes up by approx. 10 MB. The strange thing is 
however that when closing the form again (still without doing any 
rendering) this memory is not released, even though the destructor of 
the vtkBorlandRenderWindow was called...

Furthermore; if I create a subsequent instance of the form, memory 
consumption increases by an additional ~2 MB, which is also not released 
upon destruction.

So my questions is really if anyone has any idea of what is going on 
here...(?) Is this leak caused by opengl, or am I missing something?


Kind regards,
Anders Vestbo

Here are the functions called in vtkBorlandRenderWindow:

//---------------------------------------------------------------------------
vtkWin32RenderWindowInteractor * __fastcall 
TvtkBorlandRenderWindow::GetInteractor(void)
{
   if (FRenderWindow)
     {
     if (!FInteractor)
       {
       throw Exception("Window exists but no Interactor, this shouldn't 
happen");
       }
     }
   else
     {
     this->GetRenderWindow();
     }
   return FInteractor;
}

//---------------------------------------------------------------------------

vtkRenderer * __fastcall TvtkBorlandRenderWindow::GetRenderer(void)
{
   if (!FRenderer)
     {
     FRenderer = vtkRenderer::New();
     GetRenderWindow()->AddRenderer(FRenderer);
     FRenderer->ResetCamera();
     DWORD  L = ColorToRGB(Color);
     float rgb[3] = { GetRValue(L)/255.0, GetGValue(L)/255.0, 
GetBValue(L)/255.0 };
     FRenderer->SetBackground(rgb);
     }
   return FRenderer;
}

//---------------------------------------------------------------------------

vtkWin32OpenGLRenderWindow * __fastcall 
TvtkBorlandRenderWindow::GetRenderWindow(void)
{
   if ( ! FRenderWindow )
     {
     // Stuff the renderwindow into our window
     FRenderWindow = vtkWin32OpenGLRenderWindow::New();
     FRenderWindow->AddObserver( vtkCommand::AbortCheckEvent, 
FAbortCallback);
     FRenderWindow->SetParentId(Parent->Handle);
     FRenderWindow->SetWindowId(Handle);
     FRenderWindow->DoubleBufferOn();
     FRenderWindow->SwapBuffersOn();
     // Frame to avoid unsightly garbage during initial
     // display which may be long when a complex scene is first rendered
     FRenderWindow->Frame();
     Invalidate();
     }
     // We create the interactor here because it makes maintenance better
   if (!FInteractor)
     {
     FInteractor = vtkWin32RenderWindowInteractor::New();
     FInteractor->SetRenderWindow(FRenderWindow);
     FInteractor->SetInstallMessageProc(false);
     SetInteractorMode(FInteractorMode);
     FInteractor->UpdateSize(Width,Height);
     FInteractor->Initialize();
     }
   return FRenderWindow;
}



__fastcall TvtkBorlandRenderWindow::~TvtkBorlandRenderWindow()
{
     // Delete this first because Renderwindow has a hold on it too
   if ( FInteractor )
     {
     FInteractor->Delete();
     FInteractor = 0;
     }
   if ( FRenderer )
     {
     FRenderer->GetProps()->RemoveAllItems();
     FRenderWindow->RemoveRenderer(FRenderer);
     FRenderer->Delete();
     FRenderer = 0;
     }
   if ( FRenderWindow )
     {
     FRenderWindow->RemoveObserver(FAbortCallback);
     FRenderWindow->Delete();
     FRenderWindow = 0;
     }
   FAbortCallback->Delete();
}



More information about the vtkusers mailing list