[vtkusers] Difference between vtkSmartPointer assignment operator and ShallowCopy
Elvis Stansvik
elvis.stansvik at orexplore.com
Thu Oct 25 03:45:16 EDT 2018
Den tors 25 okt. 2018 kl 04:46 skrev Berti Krüger <berti_krueger at hotmail.com>:
>
> Am Do, 25. Okt, 2018 um 3:37 VORMITTAGS schrieb Oleksandr Malyushytsky <omalyushytskyvtkuser at gmail.com>:
>
> }
>
>
> Thanks Oleksandr for the clarification and the good example!
Funny that this would come up. I recently tracked down an unusually
high memory usage in our application. It turned out it was simple
matter of us not "terminating" a pipeline at the right place in a
function that creates an image data (valgrind's massif tool led me to
it).
E.g. we had something like
vtkSmartPointer<vtkVolume> createVolume(....) {
auto reader = vtkSmartPointer<OurImageReader>::New();
...
auto extract = vtkSmartPointer<vtkExtractVOI>::New();
extract->SetInputConnection(reader->GetOutputPort());
...
auto threshold = vtkSmartPointer<vtkImageThreshold>::New();
threshold->SetInputConnection(extract->GetOutputPort());
...
auto mapper = vtkSmartPointer<vtkGPUVolumeRayCastMapper>::New();
mapper->SetInputConnection(threshold->GetOutputPort());
...
auto volume = vtkSmartPointer<vtkVolume>::New();
volume->SetMapper(mapper);
volume->Update();
...
return volume;
}
In this case, we had no need for keeping around the
reader/extract/threshold part of the pipeline, but since there there
were back-references back through the pipeline, these elements were
kept around and the copies of the data that they had were taking up
pretty big chunks of memory (or well, at least the threshold filter
did if I remember correctly).
The solution was simply to change
auto threshold = vtkSmartPointer<vtkImageThreshold>::New();
threshold->SetInputConnection(extract->GetOutputPort());
...
auto mapper = vtkSmartPointer<vtkGPUVolumeRayCastMapper>::New();
mapper->SetInputConnection(threshold->GetOutputPort());
...
to
auto threshold = vtkSmartPointer<vtkImageThreshold>::New();
threshold->SetInputConnection(extract->GetOutputPort());
threshold->Update();
...
auto mapper = vtkSmartPointer<vtkGPUVolumeRayCastMapper>::New();
mapper->SetInputData(threshold->GetOutput());
...
in order to "cut off" the pipeline and let those parts of the pipeline
destruct when the function returns.
Just thought I should mention this as a potential gotcha, where you're
looking for issues where the memory usage is unusually high.
Elvis
>
>
> Cheers,
>
> Berti
>
> _______________________________________________
> 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
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> https://public.kitware.com/mailman/listinfo/vtkusers
More information about the vtkusers
mailing list