[vtkusers] SmartPointer does not seem to free memory!? Bug!?

itkvtk123 at gmx.net itkvtk123 at gmx.net
Wed Dec 9 21:34:38 EST 2009


Hey vtkusers,

today I encountered a problem, that local vtk smartpointers seem not to free their memory after they go out of scope.
I wrote a minimal example to illustrate my problem:


#include "vtkOrientedGlyphContourRepresentation.h"
#include "vtkImageViewer2.h"
#include <iostream>

int main()
{
	for(int i = 999; i >= 0; i--)
	{
		std::cout << i << std::endl;

		vtkOrientedGlyphContourRepresentation* contour = vtkOrientedGlyphContourRepresentation::New();
		contour->SetRenderer(vtkImageViewer2::New()->GetRenderer());
	}

	//idle
	int wait;
	std::cin >> wait;

	return 0;
}

This code creates 999 times a local vtk-contour and a local vtkImageviewer and adds the renderer of the viewer to the contour.
Since all variables are local, I would expect that it gets destroyed after the for-loop is over.
(actually I would even expect it gets destroyed after each iteration)

But when I have a look at the memory usage, it does not seem to free anything! This for loop (999 times) causes about 130 MB, which are still in use when I reach the input line (std::cin).

Do I miss something?
Why does something like

void myFunction()
{
 vtkImageViewer2::New();
}

eat up memory???


Thanks a lot guys.
Bye
-- 
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01



More information about the vtkusers mailing list