[vtkusers] vtkImageReslice memory leak problem
David Gobbi
david.gobbi at gmail.com
Fri Apr 6 08:58:01 EDT 2012
Try VTK_DEBUG_LEAKS. That's my advice.
- David
On Fri, Apr 6, 2012 at 2:26 AM, ysa0829 <ysa0829 at gmail.com> wrote:
> Hello David,
>
> Since vtkImageReslice is the subclass of vtkThreadedImageAlgorithm, I am
> wondering if the memory leak has something to do with multithreads.
>
> I tried to limit the number of threads of imagereslice into one (i.e.:
> reSlice->SetNumberOfThreads(1); ) The memory leak problem went away as
> follows:
>
> //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//
> for(int i = 0 ; i < 100000000 ; i++)
> {
> vtkImageReslice *reSlice = vtkImageReslice::New();
> reSlice->SetInput(image);
> reSlice->SetNumberOfThreads(1); // with this line, no more memory leak
> 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(); // after delete, Threader under
> vtkThreadedImageAlgorithm becomes 0xfeeefeee, however if not using
> "reSlice->SetNumberOfThreads(1)", memory leak still happens (Threader still
> becomes 0xfeeefeee after deleted)
> }
> //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑//
>
> I think there might be bug existing in vtkThreadedImageAlgorithm, though I
> couldn't be sure the reason.
>
> Also I have noticed that
> http://web.archiveorange.com/archive/v/50zHjPu4zHhThzhgTtcR
> you mentioned that vtkImageReslice has some issues in threads 11 years ago,
> also you have contributed efforts to vtkImageRelice for v5.10, I believe
> that you definitely have better understanding about threads mechanism in
> VTK.
>
> Your kind assistance will be deeply appreciated.
>
> Following is my code for your reference again:
>
> 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 < 100000000 ; i++)
> {
> vtkImageReslice *reSlice = vtkImageReslice::New();
> reSlice->SetInput(image);
> reSlice->SetNumberOfThreads(1); // with this line, no more memory leak
> 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(); // after delete, Threader under
> vtkThreadedImageAlgorithm becomes 0xfeeefeee, however if not using
> "reSlice->SetNumberOfThreads(1)", memory leak still happens (Threader still
> becomes 0xfeeefeee after deleted)
> }
> }
> //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑//
>
>
>
>
>
>
>
> --
> View this message in context: http://vtk.1045678.n5.nabble.com/vtkImageReslice-memory-leak-problem-tp5584699p5622332.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