[vtkusers] Memory leak

Jonathan Morra jonmorra at gmail.com
Tue Mar 27 11:10:24 EDT 2012


I posted this problem before, but got no response.  I've slightly modified
my test program to illustrate the problem more clearly.  Specifically, when
I run the below code on Windows 7 compiled with MSVC 2008 in 32 bit with Qt
4.7.4 and VTK pulled from git master on March 5, 2012, I get a pretty
pronounced memory leak.  As I mouse over the image, then memory in the
Windows Task Manager climbs.  If I comment out the imageViewer->Render();
line then the memory stays constants.

Can someone please
1.  Verify that they see this on their machine as well
2.  Provide a way to fix it.

Thanks

#include <QtGui/QApplication>

#include <QMainWindow>

 #include <QVTKWidget2.h>

#include <vtkImageViewer2.h>

#include <vtkImageData.h>

#include <vtkPointData.h>

#include <vtkGenericOpenGLRenderWindow.h>

 class MyQVTKWidget2 : public QVTKWidget2 {

public:

    MyQVTKWidget2 (vtkImageViewer2 *imageViewer, QWidget *parent = 0)
: QVTKWidget2(parent) {

        this->imageViewer = imageViewer;

    }

     virtual ~MyQVTKWidget2() {

        imageViewer->Delete();

    }

     void mouseMoveEvent(QMouseEvent *) {

        for (int i=0; i<1000; ++i) {

            // Comment out these lines to see the memory stay constant

            imageViewer->Render();

        }

    }

 private:

    vtkImageViewer2 *imageViewer;

};

 int main(int argc, char *argv[]) {

    QApplication a(argc, argv);

     vtkImageData *imageData = vtkImageData::New();

    imageData->SetExtent(0, 100, 0, 100, 0, 100);

    imageData->SetOrigin(0, 0, 0);

    imageData->SetSpacing(1, 1, 1);

    imageData->AllocateScalars();

    imageData->GetPointData()->GetScalars()->FillComponent(0, 0);

     vtkImageViewer2 *imageViewer = vtkImageViewer2::New();

    imageViewer->SetInput(imageData);

     MyQVTKWidget2 *widget = new MyQVTKWidget2(imageViewer);

    imageViewer->SetRenderWindow(widget->GetRenderWindow());

     QMainWindow mainWindow;

    mainWindow.setGeometry(200, 200, 300, 300);

    mainWindow.setCentralWidget(widget);

    mainWindow.show();

     imageData->Delete();

    return a.exec();

}


Here is the Qt .pro file as well if it helps


#-------------------------------------------------

#

# Project created by QtCreator 2012-02-24T13:30:58

#

#-------------------------------------------------

 QT       += core opengl gui

 TARGET = QVTKWidget2Test

CONFIG   += console

CONFIG   -= app_bundle

 TEMPLATE = app

 SOURCES += main.cpp

 LIBS    += -L../../vtk/lib -lvtkCommon -lvtksys -lQVTK\

 -lvtkViews -lvtkWidgets -lvtkInfovis -lvtkRendering -lvtkGraphics
-lvtkImaging -lvtkIO -lvtkFiltering\

 -lvtklibxml2 -lvtkDICOMParser -lvtkpng -lvtkpng -lvtktiff -lvtkzlib
-lvtkjpeg -lvtkalglib -lvtkexpat\

 -lvtkverdict -lvtkmetaio -lvtkNetCDF -lvtksqlite -lvtkexoIIc
-lvtkftgl -lvtkfreetype -lvtkHybrid\

 -lvtkVolumeRendering

 INCLUDEPATH += ../vtk/include
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120327/afd1324b/attachment.htm>


More information about the vtkusers mailing list