[vtkusers] bug? strange memory usage with multiple render windows

N Smethurst nick.smethurst at free.fr
Fri Feb 14 07:49:59 EST 2003


Hello again list..

I am working on an application that uses multiple render windows and have 
noticed that memory is leaked on each render window destruction. VTK's leak 
detection reports nothing and manual examination of object reference counts 
confirms that my code seems to be functioning correctly. I have tried nightly 
builds from 17/01/03 (using cmake 1.4) and 09/02/03 (using cmake 1.6) on 
mandrake linux 9.0.

I am sorry if this email is rather long but I feel that I should be specific 
and detailed. Here is a piece of code to illustrate this behaviour. The code 
doesn't do anything apart from creating render windows and deleting them 
after rendering once, pausing between actions so I can record memory usage:

///////////////////start code///////////////////
#include <vtkConeSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <stdio.h>

int main()
{
    vtkConeSource *cone = vtkConeSource::New();
    vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
    mapper->SetInput(cone->GetOutput());
    vtkActor *actor = vtkActor::New();
    actor->SetMapper(mapper);

    // create first window
    vtkRenderer *ren1 = vtkRenderer::New();
    ren1->AddActor(actor);
    vtkRenderWindow *renWin1 = vtkRenderWindow::New();
    renWin1->AddRenderer(ren1);
    renWin1->Render();

    // correct reference counts
    cone->Delete();
    mapper->Delete();
    actor->Delete();
    ren1->Delete();

    cout << "Created objects and first renderer & renWin.\n";
    // pause to check memory usage
    char temp;
    cin >> temp;

    // create second window
    vtkRenderer *ren2 = vtkRenderer::New();
    ren2->AddActor(actor);
    vtkRenderWindow *renWin2 = vtkRenderWindow::New();
    renWin2->AddRenderer(ren2);
    ren2->Delete();
    renWin2->Render();
    cout << "Created second renderer and renWindow.\n";
    cin >> temp;

    // create third window
    vtkRenderer *ren3 = vtkRenderer::New();
    ren3->AddActor(actor);
    vtkRenderWindow *renWin3 = vtkRenderWindow::New();
    renWin3->AddRenderer(ren3);
    ren3->Delete();
    renWin3->Render();
    cout << "Created third renderer and renWindow.\n";
    cin >> temp;

    // create fourth window
    vtkRenderer *ren4 = vtkRenderer::New();
    ren4->AddActor(actor);
    vtkRenderWindow *renWin4 = vtkRenderWindow::New();
    renWin4->AddRenderer(ren4);
    ren4->Delete();
    renWin4->Render();
    cout << "Created fourth renderer and renWindow.\n";
    cin >> temp;

    // delete one by one in order to record memory usage
    renWin4->Delete();
    cout << "Deleted fourth ren window.\n";
    cin >> temp;

    renWin3->Delete();
    cout << "Deleted third ren window.\n";
    cin >> temp;

    renWin2->Delete();
    cout << "Deleted second ren window.\n";
    cin >> temp;

    renWin1->Delete();
    return 0;
}
///////////////////end code///////////////////

I get the following memory usage with the 17/01/03 nightly build:

                            total        difference       leak size       
                        VmSize  VmRss   VmSize  VmRss   VmSize  VmRss
one window created      165016  14268                           
two windows created     166556  14828     1540    560             
three windows created   168084  15364     1528    536             
four windows created    169612  15904     1528    540             
fourth window deleted   167996  15356    -1616   -548      -88     -8
third window deleted    166776  15032    -1220   -324      308    212
second window deleted   165552  14704    -1224   -328      316    232
                                          total leak:      536    436

With the 09/02/03 nightly build, I get the following:

                            total        difference       leak size       
                        VmSize  VmRss   VmSize  VmRss   VmSize  VmRss
one window created       29528  11244                           
two windows created      32892  12392     3364   1148            
three windows created    36256  13524     3364   1132            
four windows created     39624  14652     3368   1128            
fourth window deleted    38924  14412     -700   -240     2668    888
third window deleted    application crashes      with error:
   XIO:  fatal IO error 9 (Bad file descriptor) on X server ":0.0"
         after 362 requests (361 known processed) with 0 events remaining.

(However, this crash does not happen in my application!)

Running a piece of non-vtk code with
    int* a=new int[50000];
and
    delete []a;
commands in place of the vtk creation/deletion results in the following:
   
                            total        difference       leak size       
                        VmSize  VmRss   VmSize  VmRss   VmSize  VmRss
ready to create..        29044  12896                           
one created              29240  13100      196    204             
two created              29436  13296      196    196             
three created            29632  13492      196    196             
fourth created           29828  13688      196    196             
fourth deleted           29632  13492     -196   -196        0      0
third deleted            29436  13296     -196   -196        0      0
second deleted           29240  13100     -196   -196        0      0
first deleted            29044  12904     -196   -196        0      8
                                          total leak:        0      8

hence the memory management of the kernel seems to be working correctly.

In my actual application, if render windows are repeatidly created and 
distroyed, the memory usage climbs and climbs and is not released until the 
whole application is closed.

I have noticed that I get the following warning messages when running my 
application and closing a window. I'm not sure if they are relevant. They do 
not appear when running the code given here:

Generic Warning: In /home/nic/comp/VTK/VTK/Common/vtkDebugLeaks.cxx, line 280
Deleting unknown object: vtkXOpenGLRenderWindow
Generic Warning: In /home/nic/comp/VTK/VTK/Common/vtkDebugLeaks.cxx, line 280
Deleting unknown object: vtkRenderWindowInteractor

Kind regards

Nick




More information about the vtkusers mailing list