[vtkusers] vtkImageReslice memory leak problem

ysa0829 ysa0829 at gmail.com
Sun Apr 22 21:27:06 EDT 2012


Hello David,

Sorry for the late response, it took my team a while to confirm the possible
cause of the memory leak problem while using vtkImageReslice and QT
"QFileSystemModel" at the same time.

My conclusion is that it's very likely to be incurred by Intel's multi
thread core design, the testing result from the CPUs we can collect (each
was tested at least two machines) is listed below:

CPUs all tested wtih my code:

showing memory leaks
1.Intel Core 2 Quad CPU Q9550 @ 2.83GHz 2.83GHz
2.Intel Core i7-2670QM CPU @2.20GHz 2.20GHz
3.Intel Core i7-2600K CPU @ 3.40GHz 3.40GHz
4.Intel Core i7-2635QM CPU @ 2.00GHz 2.00GHz

showing NO memory leak
1.Intel Core 2 Duo CPU T9400 @ 2.53GHz 2.53GHz
2.Intel Core i7-2640M CPU @ 2.80GHz 2.80GHz
3.Intel Core i7-2630QM CPU @ 2.00GHz 2.00GHz
4.Intel Core i5-460M CPU @ 2.53GHz 2.53GHz 
5.Intel Core 2 Duo Processor T7500 (4M Cache, 2.20 GHz, 800 MHz FSB) 

As I perceived, even at the same batch of CPUs (such as i7 2630QM and
2670QM) showing different results.

I have used VTK_DEBUG_LEAKS, and it did not detect memory leaks for all
CPUs.

Following is my code:
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)
	}
}
//↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑//

Anne.

--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkImageReslice-memory-leak-problem-tp5584699p5658209.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list