[vtkusers] Memory management : pointer on VTK object

Malsoaz James jmalsoaz at yahoo.fr
Thu Jul 4 03:33:40 EDT 2013


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130704/b98990c6/attachment.htm>


More information about the vtkusers mailing list