[Insight-users] Failed to allocate memory for image

Luis Ibanez luis.ibanez at kitware.com
Mon Aug 27 12:09:22 EDT 2007


Hi Ashish,

What version of ITK are you using ?

   This looks like a memory leak...

Note that you really don't have to create
the reader an the GDCMImage IO at every
iteration of the loop. That being said,
your code is still a valid construction.

Do you get the same error if you suppress
the code that is "oprocessing information from
header of each image" ?

It may be that that section of code contains
a memory leak...


   Please let us know


      Thanks


          Luis


--------------------
Ashish Singh wrote:
> Hi,
> 
> I have written an application to read and process dicom header 
> information. My application runs fine for small number of images but 
> gives an error when it reaches about 70,000 images(the number varies 
> each time).
> The error that I get is the following:
> ---------------
> itk::ExceptionObject <01C5AC80>
> Location: "unsigned char *_thiscall itk::ImportImageContainer<unsigned 
> long,unsigned char>::AllocateElements<unsigned long> const"
> File: 
> c:\myinstalls\insighttoolkit-3.2.0\code\common\itkImportImageContainer.txx
> 
> Line: 188
> Description: Failed to allocate memory for image.
> ---------------
> 
> The images don't belong to a single series.The application is running on 
> windows XP Pro x64 platform. The relevant portion of the code looks like 
> this -
> --------
> const unsigned int InputDimension =3;
> typedef unsigned char InputPixelType;
> typedef itk::Image< InputPixelType, InputDimension > InputImageType;
> typedef itk::ImageFileReader< InputImageType > ReaderType;
> typedef itk::GDCMImageIO ImageIOType;
> 
> unsigned long fni;
> for(fni=0;fni<250000;fni++)
> {
> 
>     ReaderType::Pointer reader2 = ReaderType::New();
> 
>     ImageIOType::Pointer gdcmImageIO2 = ImageIOType::New();
>         
>     [set filename for reader2]
>     //fname = this->directory->absoluteFilePath(this->files[fni]);
>     //reader2->SetFileName(std::string( fname.toAscii()));
> 
>     reader2->SetImageIO(gdcmImageIO2);
>     try
>     {
>         reader2->Update();
>     }
>     catch (itk::ExceptionObject & e)
>     {
>         std::cerr << "exception in file reader " << std::endl;
>         std::cerr << e << std::endl;
>         return EXIT_FAILURE;
>     }
> 
>     [ code for processing information from header of each image here]
> 
>     //reader2->Delete();//not implemented
>     //gdcmImageIO2->Delete();//not implemented
> 
> }
> ----------
> I cannot call a delete inside the 'for' loop. It gives me an error 
> saying that an error has occured and do you want to send information to 
> Microsoft?
> I also did some reading in ITK software guide, where it says that a 
> smart pointer takes care of delete by itself. I also tried Register(), 
> UnRegister(), ReleaseDataFlagOn().None of these work.
> Can anyone please tell me what is going wrong here and how to fix it? 
> How can I release the memory for the reader? Is there a simpler way to 
> do this?
> I will really appreciate if someone can help me with this.
> 
> Thanks,
> Ashish
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users


More information about the Insight-users mailing list