[vtkusers] Memory leak

Hal Canary hal at cs.unc.edu
Tue May 15 10:30:04 EDT 2012


On 05/15/2012 10:19 AM, Jothybasu Selvaraj wrote:
> Hi all,
>
> I have a pipeline like this, every time I call this function the memory
> increases ~10MB. How can I fix this?
>
> I have a imgData already instantiated like this
>
> vtkSmartPointer<vtkImageData>img=
>       vtkSmartPointer<vtkImageData>::New();
>
> vtkSmartPointer<vtkXMLImageReader>rd=
>       vtkSmartPointer<vtkXMLImageReader>::New();
> rd->SetFilename("filename");
> rd->Update();
>
> img=rd->GetOutput();
>
>
> //Now I repeat this function several times
>
>     vtkSmartPointer<vtkImageShiftScale>scaler=
>             vtkSmartPointer<vtkImageShiftScale>::New();
>     scaler->SetInput(img);*//is this correct way of doing?*
>
>     scaler->SetScale(0.5);//Multiply
>     scaler->SetOutputScalarTypeToDouble();
>
>     //scaler->ReleaseDataFlagOn();//Tried with this too
>     scaler->Update();
>
>     img=scaler->GetOutput();*//is this correct way of doing?*
>
> I am beginner in C++, so I am expecting some silly mistakes.
>

Nine out of ten times , you want to do
	b->SetInputConnection(a->GetOutputPort());
instead of
	b->SetInput(a->GetOutput());

See http://www.vtk.org/Wiki/VTK/FAQ .

Is this what you want to do?

vtkSmartPointer<vtkXMLImageReader>rd=
      vtkSmartPointer<vtkXMLImageReader>::New();
rd->SetFilename("filename");
rd->Update();
vtkAlgorithmOutput * outputPort = rd->GetOutputPort();

//Now I repeat this function several times
   {
   vtkSmartPointer<vtkImageShiftScale>scaler=
           vtkSmartPointer<vtkImageShiftScale>::New();
   scaler->SetInputConnection(outputPort);
   scaler->SetScale(0.5);//Multiply
   scaler->SetOutputScalarTypeToDouble();
   scaler->Update();
   outputPort = scaler->GetOutputPort();
   }

//then
do_something_with(outputPort);


-- 
Hal Canary
http://cs.unc.edu/~hal/



More information about the vtkusers mailing list