[vtkusers] memory problems
Bruno
bant1708 at yahoo.com.br
Thu Nov 18 12:54:41 EST 2004
Hi all,
I'm having a strange problem about memory allocation. I'm using a
gaussian filter many times in a loop. After some iterations, this loop
fails and raise following exception, meaning that it can't allocate more
memory:
"std::bad_alloc with message 'Exception Object Address: 0x6CBBE156"
So, I checked with the task manager of Windows the of
allocation/deallocation of the memory of my program and I notice that
when it is performing the gaussian smooth, the consumption of the memory
increases, as expected. When the next filter (vtkMarchingCubes) is
executed, the amount of memory allocated previously by the gaussian
filter is released, as expected (I'm using the function
ReleaseDataFlagOn() ). The next command of the pipeline is the
vtkStripper. I don't delete this object because I intend to use it in
others functions of my program. After all, the program returns to the
beginning of the loop and repeats the process. But, after some
iterations, it raises the exception explained above.
What I can't understand is why VTK can't allocate memory when there are
a lot of memory available!! Moreover, in the same program, after the
exception above is raised, I can allocate a huge vector of int like "
int *a = new int[10000000] ". How can I, in the same program, allocate
memory using 'new' and vtk don't?
I'm using vtk 4.4, Borland C++ Builder 6.0 PE and Windows XP SP2. I
think the problem is caused by Boland Builder. Can anyone confirm that?
If someone want to test this bug, I prepared the following code.
Thanks. Bruno.
#include <vcl.h>
#include "main.h"
#include "vtkImageThreshold.h"
#include "vtkContourFilter.h"
#include "vtkMarchingCubes.h"
#include "vtkImageData.h"
#include "vtkDoubleArray.h"
#include "vtkImageGaussianSmooth.h"
#include "vtkStripper.h"
#include "vtkPointData.h"
#include "vtkPolyData.h"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
vtkImageThreshold *selectIsoValue;
// vtkContourFilter *ContourFilter;
vtkMarchingCubes *ContourFilter;
vtkStripper *stripper;
int dim[3];
dim[0] = 368;
dim[1] = 220;
dim[2] = 176;
int n=10;
vtkImageData *vol = vtkImageData::New();
vol->ReleaseDataFlagOff();
vol->SetSpacing(1,1,1);
vol->SetDimensions(dim);
vol->SetScalarTypeToDouble();
vtkDoubleArray *scalars = vtkDoubleArray::New();
scalars->SetNumberOfComponents(1);
scalars->SetNumberOfTuples(dim[0]*dim[1]*dim[2]);
scalars->FillComponent(0,15);
vol->GetPointData()->SetScalars(scalars);
for (int i=0;i<n;i++){
vtkImageGaussianSmooth *gaussian = vtkImageGaussianSmooth::New();
gaussian->SetStandardDeviations(3,3,3);
gaussian->SetRadiusFactors(1.5,1.5,1.5);
gaussian->SetInput(vol);
gaussian->GetOutput()->ReleaseDataFlagOn(); // !! ON !!
gaussian->Update();
// selecting an isosurface
ContourFilter = vtkMarchingCubes::New();
ContourFilter->SetInput(gaussian->GetOutput());
ContourFilter->ComputeScalarsOff();
ContourFilter->ComputeNormalsOff();
ContourFilter->ComputeGradientsOff();
ContourFilter->SetNumberOfContours(1);
// ContourFilter->SetValue(0,10);
ContourFilter->GetOutput()->ReleaseDataFlagOn();
ContourFilter->Update();
// make triangles strips
stripper = vtkStripper::New();
stripper->SetInput(ContourFilter->GetOutput());
stripper->GetOutput()->ReleaseDataFlagOn();
stripper->Update();
// cleaning the memory
gaussian->Delete();
ContourFilter->Delete();
//stripper->Delete(); // I don't want to delete Stripper
}
vol->Delete();
scalars->Delete();
}
//---------------------------------------------------------------------------
More information about the vtkusers
mailing list