[vtkusers] vtkImageReslice memory leak problem

ysa0829 ysa0829 at gmail.com
Fri Apr 6 04:26:23 EDT 2012


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.



More information about the vtkusers mailing list