[vtkusers] vtk becomes slow and consumes more and more memory.

Taron taron2000 at gmx.de
Fri Aug 15 05:05:18 EDT 2014


Hi there, this is a follow-up to my memory leak question, which in fact is
not a "real" memory leak but something different. I'm using VTK 6.1 on
Windows 7 x64 compiled Visual Studio 2012 in 64Bit.

My problem is that everytime I create objects in vtk and call update on them
it takes more and more memory and runs longer and longer. Consider this
code:

#include <vtkImageConstantPad.h>
#include <vtkImageData.h>
#include <ctime>

int main(int argc, char *argv[])
{
    int c=0;
    clock_t start;
    size_t iterations = 1000;
    while (c != '.'){
         c = getchar();
         start = clock();
         for(size_t i=0; i<iterations; ++i){
             vtkImageConstantPad* pad = vtkImageConstantPad::New();
             vtkImageData* test = vtkImageData::New();
             test->SetExtent(0,1,0,1,0,1);
             test->AllocateScalars(VTK_FLOAT,1);
             pad->SetInputData(test);
             pad->SetOutputWholeExtent(0,2,0,2,0,2);
             pad->Update(); //this is what makes it bad
             pad->Delete();
             test->Delete();
         }
         std::cout << "Time for " << iterations << ": " <<
static_cast<double>(clock() - start) / CLOCKS_PER_SEC << "sec" << std::endl;
    }
    return 0;
}


The output:

Time for 1000: 0.816sec
Time for 1000: 1.879sec
Time for 1000: 3.454sec
etc.

It takes longer with every call to update and consumes more memory, but all
instances are deleted in the for-scope. So this seems to create some sort of
objects and puts into an update pipeline, but does not remove them later
internally. Can anyone confirm this behavior and other platforms and, how to
fix that?



--
View this message in context: http://vtk.1045678.n5.nabble.com/vtk-becomes-slow-and-consumes-more-and-more-memory-tp5728227.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list