[Insight-users] memory allcoation failure: I don't understand the exception

Atwood, Robert C r.atwood at imperial.ac.uk
Thu Aug 5 10:38:00 EDT 2004


Dear all:

I get an exception that indicates that memory could not be allocated, in
a routine that loops through a set of parameters for the filter and
writes an extracted slice after each try. I have tried monitoring the
memory usage and do not see anything particularly unusual leading up to
the failure. I modified my code to try to get rid of objects that are no
longer necessary to the execution of the filter, and reduced the overall
memory usage by about 500 Mb, but the same exception still occurs even
though the total memory usage does not reach what it was before. This
was done by calling Delete() on the prefilter I used, as well as freeing
the imported pointer.

The image is ~ 500 Mb 
The computer has 6Gb installed. 
Other tests show that I can allocate about 3 Gb for a single application
before problems.
The system indicates that about 1.7 Gb is in use by the application up
until failure.


Here is the relevant loop, I could post the rest of the code too if
necessary, I just hope that the problem is really obvious to someone...
I have reviewed section 3.2 especiall 3.2.4 about memory management but
it has not helped so far. It was workign with smaller images , even when
the computer memory size was smaller (2Gb) too. 

The exception occurrs at 384 below. It gets through about 30 iterations
before crashing. Here is the tail end of the output. The routine getMinf
simply prints the result of the glibc mallinfo call into the log file
and the screen. I added this after finding the crash, it does not seem
to affect the behaviour.

The system is RedHat Enterprise , gcc3.2.3, glibc glibc-2.3.2-95.20

ITK is from cvs (Jul 21 2004 checked out) 



Thanks
Robert

Output:


mallinfo arena 3096576 hblkhd 1413480448 ordblks 31 uordblks 2616592
fordblks 479984
setting watershed level 0.020000
Iteration 8 2 : l=0.020000 t=0.020000
mallinfo arena 3096576 hblkhd 1413480448 ordblks 31 uordblks 2616592
fordblks 479984
Printing slice
mallinfo arena 3096576 hblkhd 1413480448 ordblks 31 uordblks 2616592
fordblks 479984
setting watershed level 0.010000
Iteration 9 2 : l=0.010000 t=0.020000
mallinfo arena 3096576 hblkhd 1413480448 ordblks 31 uordblks 2616592
fordblks 479984
Printing slice
mallinfo arena 3096576 hblkhd 1413480448 ordblks 31 uordblks 2616592
fordblks 479984
setting watershed level 0.000000
Iteration 10 2 : l=0.000000 t=0.020000
mallinfo arena 3096576 hblkhd 1413480448 ordblks 31 uordblks 2616592
fordblks 479984
Printing slice
mallinfo arena 3096576 hblkhd 1413480448 ordblks 31 uordblks 2616592
fordblks 479984
setting watershed threshold 0.030000
setting watershed level 0.100000
Iteration 0 3 : l=0.100000 t=0.030000
mallinfo arena 3096576 hblkhd 1413480448 ordblks 31 uordblks 2616592
fordblks 479984
Printing slice
Exception caught 01 !
Exiting !

itk::ExceptionObject (0xb7200538)
Location: "ImportImageContainer::AllocateElements"
File:
/usr/local/encap/ITK_1.8.0.8/include/InsightToolkit/Common/itkImportImag
eContainer.txx
Line: 186
Description: Failed to allocate memory for image.



Some code :

(using imported image -> prefilter(nonlin. diffusion) -> placed in image
object

deleting prefilter and free import buffer

then imageobject->watershed->slicer->colormapper->filewriter) 






    340 /* add slicer to the pipe line */
    341   slicer->SetInput ( watershed->GetOutput());
    342
    343
    344
    345 for (j=jstart;j<=jend;j++){
    346      thresh = tstart + (tstep * (float)(j)) ;
    347      printf("setting watershed threshold %f\n",thresh);
    348      fprintf(logfile,"setting watershed threshold %f\n",thresh);
    349      watershed->SetThreshold(thresh);
    350
    351
    352 for(i=istart;i<=iend;i++){
    353 /* level should decrement if looping, instead of increment */
    354 /* according to the itk guide, this avoids redoing the
watersheds*/
    355      level = wstart - (wstep * (float)(i)) ;
    356      printf("setting watershed level %f\n",level);
    357      fprintf(logfile,"setting watershed level %f\n",level);
    358
    359      watershed->SetLevel( level );
    360
    361
    362      printf("Iteration %i %i : l=%f t=%f\n",i,j,level,thresh);
    363      fprintf(logfile,"Iteration %i %i : l=%f
t=%f\n",i,j,level,thresh);
    364
    365         /* set up the slice writer */
    366
snprintf(slicename,255,"slice%03i_l%03i_t%03i_%s.png",sliceNumber,i,j,ct
rl->outfile);
    367
    368      colormapperslice->SetInput(slicer->GetOutput());
    369      slicewriter->SetInput(colormapperslice->GetOutput());
    370           slicewriter->SetFileName(slicename);
    371
    372          // slicemedian->SetInput(slicer->GetOutput());
    373
    374
    375
    376           getMinf(stdout);
    377           getMinf(logfile);
    378
    379         /* process the slice */
    380           printf("Updating filter pipeline and printing
slice\n");
    381           fprintf(logfile,"Updating filter pipeline and printing
slice\n");
    382           try
    383             {
    384             slicewriter->Update();
    385             }
    386           catch( itk::ExceptionObject & exp )
    387             {
    388           std::cerr << "Exception caught 01 !" << std::endl;
    389           std::cerr << "Exiting !" << std::endl;
    390           std::cerr << exp << std::endl;
    391           exit(0);
    392             }
    393           getMinf(stdout);
    394           getMinf(logfile);
    395
    396  } /* i */
    397 } /* j */





More information about the Insight-users mailing list