[vtkusers] vtkImageReslice memory leak problem

David Gobbi david.gobbi at gmail.com
Thu Apr 5 23:45:18 EDT 2012


Hi Anne,

Try compiling VTK with VTK_DEBUG_LEAKS turned on in CMake.
Then run your program from the command shell.  Depending on what
kind of leak you have, this might give clues about why the leak is
occurring.  It will print out any leaked objects when your program exits.

 - David


On Thu, Apr 5, 2012 at 9:13 PM, ysa0829 <ysa0829 at gmail.com> wrote:
> Dear all,
>
> I found that there might exist memory leak problem when using
> vtkImageReslice along with QT class "QFileSystemModel"
>
> Following is a simple testing program using VTK 5.8.0, QT 4.8.1 compiled
> under VS2010 as 32 bit release running under 64 bit Win7 environment.
>
> header file:
>
> //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//
> #ifndef QTENVIRONMENT_H
> #define QTENVIRONMENT_H
>
> #include <QtGui/QMainWindow>
> #include "ui_qtenvironment.h"
>
> class vtkImageData;
> class QTEnvironment : public QMainWindow
> {
>        Q_OBJECT
>
> public:
>        QTEnvironment(QWidget *parent = 0, Qt::WFlags flags = 0);
>        ~QTEnvironment();
>
>        vtkImageData *image;
>        QFileSystemModel *model;
> private:
>        Ui::QTEnvironmentClass ui;
>
> public slots:
>        void testcode1();
> };
>
> #endif // QTENVIRONMENT_H
> //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑//
>
> .cpp file:
>
> //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//
> #include "stdafx.h"
> #include "qtenvironment.h"
> #include "vtkDICOMImageReader.h"
> #include "vtkImageReslice.h"
> #include "vtkImageData.h"
> QTEnvironment::QTEnvironment(QWidget *parent, Qt::WFlags flags)
>        : QMainWindow(parent, flags)
> {
>        ui.setupUi(this);
>        QObject::connect(this->ui.actionTestcode1, SIGNAL(triggered()), this,
> SLOT(testcode1()));
>
>        image = vtkImageData::New();
>
>        //doing this code causes memory leak
>        model = new QFileSystemModel(this);
>        QStringList filters;
>        filters << "*.dcm";
>        model->setFilter( QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot );
>        model->setNameFilters(filters);
>        model->setNameFilterDisables(false);
> }
> QTEnvironment::~QTEnvironment()
> {
>        image->Delete();
>        model->deleteLater();
> }
>
> void QTEnvironment::testcode1()
> {
>        //loading image
>        std::string folder = "c:\\1";//DICOM PATH
>        vtkDICOMImageReader *reader = vtkDICOMImageReader::New();
>        reader->SetDirectoryName(folder.c_str());
>        reader->FileLowerLeftOn();
>        reader->Update();
>
>        //deepcopy
>        image->DeepCopy(reader->GetOutput());
>        reader->Delete();
>
>        //ImageResliceTest
>        for(int i =0; i< 100000000000000;i++)
>        {
>                vtkImageReslice *reSlice = vtkImageReslice::New();
>                reSlice->SetInput(image);
>                reSlice->SetInterpolationModeToCubic();
>                reSlice->SetOutputSpacing(0.5, 0.5,0.5);
>                reSlice->SetOutputOrigin(0, 0, 0);
>                reSlice->SetOutputExtent(0, 10, 0, 10, 0, 0);
>                reSlice->Update();
>                reSlice->Delete();
>        }
> }
> //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑//
>
> While I used vtkImageReslice alone (new one instance and delete it) without
> running QT class "QFileSystemModel", there wasn't memory leak problem any
> more as follows:
>
> //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//
> for(int i = 0 ; i < 100000000000000 ; i++)
>        {
>                vtkImageReslice *reSlice = vtkImageReslice::New();
>                reSlice->SetInput(image);
>                reSlice->SetInterpolationModeToCubic();
>                reSlice->SetOutputSpacing(0.5, 0.5,0.5);
>                reSlice->SetOutputOrigin(0, 0, 0);
>                reSlice->SetOutputExtent(0, 10, 0, 10, 0, 0);
>                reSlice->Update();
>                reSlice->Delete();
>        }
> //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑//
>
> Yet when I new one "QFileSystemModel" instance in the code, however with
> nothing related to the code regarding "vtkImageReslice", then I performed
> the code as above, each time I new "vtkImageReslice" then delete it, there
> will be about 100 k memory leak adding up.
>
> //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//
>        //doing this code causes memory leak
>        model = new QFileSystemModel(this);
>        QStringList filters;
>        filters << "*.dcm";
>        model->setFilter( QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot );
>        model->setNameFilters(filters);
>        model->setNameFilterDisables(false);
> //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑//
>
> Please help, thanks in advance!
>
> Anne.
>
>
> --
> View this message in context: http://vtk.1045678.n5.nabble.com/vtkImageReslice-memory-leak-problem-tp5584699p5621965.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers


More information about the vtkusers mailing list