[vtkusers] Memory management : pointer on VTK object

Alex Malyushytskyy alexmalvtk at gmail.com
Fri Jul 5 18:01:19 EDT 2013


Try to add
SetSource(NULL);
calls after you register polydata

polydata->Register(NULL);
polydata->SetSource(NULL);
.....
output->Register(NULL);
output->SetSource(NULL);

Another source of extra memory usage may be memory granularity,
If you say that DeepCopy helps it means deleting/allocationg memory at the
same and bugger chunks helps to avoid granularity.
In this case nothing you can do.


In any case I would suggest to get

vtkTransformPolyDataFilter * trFilter = vtkTransformPolyDataFilter::New();

and
   trFilter->Delete();
out of loop.


Regards,
    Alex



On Thu, Jul 4, 2013 at 12:33 AM, Malsoaz James <jmalsoaz at yahoo.fr> wrote:

> Hi,
>
> I'm experiencing troubles when copying pointers of VTK object.
>
> Let's say I want to apply transformation to a polydata recursively like
> this:
>
>     //Read STL
>     vtkSTLReader * reader = vtkSTLReader::New();
>     reader->SetFileName("1.stl");
>     reader->Update();
>
>     vtkPolyData * polydata = reader->GetOutput();
>     polydata->Register(NULL);
>     reader->Delete();
>
>     vtkTransform * tr = vtkTransform::New();
>     tr->Translate(5, 10, 1);
>     tr->Update();
>
>     for(int i = 0 ; i < 1000 ; ++i)
>     {
>     std::cout << i << std::endl;
>     vtkTransformPolyDataFilter * trFilter =
> vtkTransformPolyDataFilter::New();
> trFilter->SetInput(polydata);
> trFilter->SetTransform(tr);
> trFilter->Update();
>
> vtkPolyData * output = trFilter->GetOutput();
> output->Register(NULL);
> trFilter->Delete();
>
> polydata->Delete();
> polydata = output;
>     }
>     tr->Delete();
>     polydata->Delete();
>
> This is working fine and I have no VTK leaks. Unfortunately, I'm noticing
> that memory for my program increases instead of remaining constant.
> What's wrong with theses few lines?
>
> By the way, using DeepCopy to save output data is working:
> polydata = vtkPolyData::New();
> polydata->DeepCopy(output);
> output->Delete();
> But I would like to avoid to deep copy data when I only need to add a
> reference to the pointer. I also would like to avoid the use of
> vtkSmartPointer.
>
> Thank you for your help
> Best.
>
>
> _______________________________________________
> 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/20130705/4107fe77/attachment.htm>


More information about the vtkusers mailing list