[vtkusers] Memory management in VTK

Benoist Laurent benoist at ibpc.fr
Mon May 10 11:52:46 EDT 2010


Hi all,

I've got a problem for freeing memory with VTK 5.2.
In my program, I've got a function that allows to switch between a  
line representation and a sphere representations.
Each time I switch, I pay attention to remove the actor from the  
renderer then delete the actor before initializing it again.

But when I use Apple Instruments to check for memory leaks, I can see  
that there is not memory leak (good point) but that the memory usage  
increases every time I switch from lines to spheres (see picture).

Does anyone have an idea of what am I doing wrong ?

Any help would be appreciated.
Thanks.
Ben.


Here is the code.

void switchRepresentationToLines()
{
	deleteActor();
	
	vtkPolyDataMapper * mapper = vtkPolyDataMapper::New();
	mapper->SetInput(_data);
	
	_actor = vtkActor::New();
	_actor->SetMapper(mapper);

	_renderer->AddActor(_actor);
	updateDisplay();
	
	mapper->Delete();
}

void switchRepresentationToSpheres()
{
	deleteActor();
	vtkSphereSource * sphereSource = vtkSphereSource::New();
	sphereSource->SetThetaResolution(10.0);
	sphereSource->SetPhiResolution(10.0);
	sphereSource->SetRadius(1.0);
	
	vtkGlyph3D * glyph = vtkGlyph3D::New();
	glyph->SetInput(_data);
	glyph->SetSourceConnection(sphereSource->GetOutputPort());
	glyph->SetVectorModeToUseNormal();
	glyph->SetScaleModeToScaleByVector();
	glyph->SetScaleFactor(0.5);
	
	vtkPolyDataMapper * mapper = vtkPolyDataMapper::New();
	mapper->ImmediateModeRenderingOn();
	mapper->SetInputConnection(glyph->GetOutputPort());
	
	_actor = vtkActor::New();
	_actor->SetMapper(mapper);
	
	_renderer->AddActor(_actor);
	updateDisplay();
	
	sphereSource->Delete();
	glyph->Delete();
}

void deleteActor()
{
	if (actor)
	{
		_renderer->RemoveActor(_actor);
		_actor->Delete();
		_actor = NULL;
	}	
}




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100510/5de7cb2c/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: leaks.png
Type: image/png
Size: 29827 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100510/5de7cb2c/attachment.png>


More information about the vtkusers mailing list