[vtkusers] Memory management in VTK

da remywendy at gmail.com
Mon May 10 20:38:43 EDT 2010


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/20100510/40b2a390/attachment.htm>


More information about the vtkusers mailing list