Severe Memory Leak

Tom Radcliffe radcliffe at igotechnologies.com
Wed May 10 22:52:51 EDT 2000


I've attached a simple example programme that produces a severe memory
leak in VTK.  The circumstances under which it occurs are unusual enough
that I can well understand how it slipped past testing, but the problem
is giving me a lot of trouble and any sage advice or clever fixes would
be really welcome.

The circumstances under which the leak occurs are as follows:  I have a
vtkActor that represents a real-world bit of machinery, and want to
present a couple of different views of it to the user.  As currently
designed, these views are shown in different render windows for simpler
integration with the native windowing system.  The configuration of the
actor is updated from real-time data that's coming in, and to get things
to re-render I call Render on the multiple render windows in a
timer-driven event loop.  The app grows with positively explosive speed.

The attached example is based on the Model.cxx example that comes with
the VTK source distribution.  I've compiled it against VTK-3.1 on both
Linux (Redhat 6.1) and Solaris 7.  The compiler is gcc-2.95.1 on both
platforms, and I used Mesa on Linux and Sun's OpenGL distribution on
Solaris.  The behaviour is identical on both platforms.

Investigation so far has shown the following:

1) If I add the renderers to a single render window and just give them
different viewports, no leaking occurs

2) I'm fairly sure the leak occurs on the call to Render on the second
render window.  The first call does not (I think) leak.

3) I'm pretty sure the leak occurs somewhere during the call to
vtkOpenGLRenderer::DeviceRender, but where exactly I haven't been able
to track down to the lower levels of the code.  Some wandering about
with gdb indicates that this may have something to do with an
interaction in the mapper that occurs when it finds itself asked to
render into a different render window than the one it already has, but I
was pretty lost by the time I got that deep.    

With a bit of fiddling I can fix my immediate problem using the fact (1)
above.  But I'm pretty sure it would be a good thing if we can find the
root cause of this behaviour and change it.

--Tom

=============================================

#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkConeSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkSphereSource.h"

void main( int argc, char *argv[] )
{
  // create two rendering windows and two renderers
  vtkRenderer *ren1 = vtkRenderer::New();
  vtkRenderWindow *renWindow1 = vtkRenderWindow::New();
  renWindow1->AddRenderer(ren1);

  vtkRenderer *ren2 = vtkRenderer::New();
  vtkRenderWindow *renWindow2 = vtkRenderWindow::New();
  renWindow2->AddRenderer(ren2);

  // create an actor and give it cone geometry
  vtkConeSource *cone = vtkConeSource::New();
  vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();
  coneMapper->SetInput(cone->GetOutput());
  vtkActor *coneActor = vtkActor::New();
  coneActor->SetMapper(coneMapper);

  // assign our actor to both renderers
  ren1->AddActor(coneActor);
  ren2->AddActor(coneActor);

  // set the locations of our windows
  renWindow1->SetPosition(0,50);
  renWindow2->SetPosition(0,300);

  // draw the resulting scene repeatedly
  while(true)
  {
    renWindow1->Render();
    renWindow2->Render();
  }

  // don't bother to clean up because we never get here
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: radcliffe.vcf
Type: text/x-vcard
Size: 364 bytes
Desc: Card for Tom Radcliffe
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20000510/4f0a90e6/attachment-0001.vcf>


More information about the vtkusers mailing list