[vtkusers] Memory management in VTK

Benoist Laurent benoist at ibpc.fr
Tue May 11 04:26:51 EDT 2010


Hi,

You both were right.
I forgot to delete the mapper in switchRepresentationToSphere().
As you said David, I was deleting vtk objects myself and the  
vtksmartpointers allow to do it automaticly.
It's quite pleasant when the answer is so blatant isn't it ?!

Thanks you all.
Ben


Le 11 mai 10 à 02:38, da a écrit :

> Youre not deleting mapper in switchRepresentationToSphere().
>
> I doubt the "Leaks" in Apple instruments will be any use in this case.
>
> On Mon, May 10, 2010 at 8:52 AM, Benoist Laurent <benoist at ibpc.fr>  
> wrote:
> 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;
> 	}	
> }
>
>
>
>
>
> _______________________________________________
> 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
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100511/373d5170/attachment.htm>


More information about the vtkusers mailing list