Hi Luis,<br><br>I ran the code suppressing header processing part and I don't get the errors. So we now know that the problem is in that part. Here is the code with that part:<br><br>--------<br>const unsigned int InputDimension =3;
<br>typedef unsigned char InputPixelType;<br>typedef itk::Image< InputPixelType, InputDimension > InputImageType;<br>typedef itk::ImageFileReader< InputImageType > ReaderType;<br>typedef itk::GDCMImageIO ImageIOType;
<br>typedef itk::MetaDataDictionary DictionaryType;<br><br>unsigned long fni;//in class header file<br>InputImageType::Pointer image;//in class header file<br>DictionaryType dictionary;//in class header file<br><br>image = InputImageType::New();//in class constructor
<br><br>for(fni=0;fni<250000;fni++)<br>{<br><br> ReaderType::Pointer reader2 = ReaderType::New();<br><br> ImageIOType::Pointer gdcmImageIO2 = ImageIOType::New();<br> <br> [set filename for reader2]<br> //fname = this->directory->absoluteFilePath(this->files[fni]);
<br> //reader2->SetFileName(std::string( fname.toAscii()));<br><br> reader2->SetImageIO(gdcmImageIO2);<br> try<br> {<br> reader2->Update();<br> }<br> catch (itk::ExceptionObject & e)<br>
{<br> std::cerr << "exception in file reader " << std::endl;<br> std::cerr << e << std::endl;<br> return EXIT_FAILURE;<br> }<br><br> [ code for processing information from header of each image from here]
<br><br> this->image=reader2->GetOutput();<br> this->dictionary=this->image->GetMetaDataDictionary();<br> this->readfiles();<br> [ code for processing information from header of each image till here]
<br><br> //reader2->Delete();//not implemented<br> //gdcmImageIO2->Delete();//not implemented<br><br>}<br><br>readfiles()<br>{<br> int flag;<br> string pid,pidtag;<br> pidtag="0010|0020";<br> DictionaryType::ConstIterator itr = this->
dictionary.Begin();<br> DictionaryType::ConstIterator end = this->dictionary.End();<br> while( itr != end )<br> {<br> itk::MetaDataObjectBase::Pointer entry = itr->second;<br> MetaDataStringType::Pointer entryvalue = dynamic_cast<MetaDataStringType *>(
entry.GetPointer() ) ;<br> if( entryvalue )<br> {<br> std::string tagkey = itr->first;<br> std::string labelId;<br> bool found = itk::GDCMImageIO::GetLabelFromTag( tagkey, labelId );<br> std::string tagvalue = entryvalue->GetMetaDataObjectValue();
<br> flag=0;<br> <br> //get patient Id in a string<br> for(i=0;i<9;i++)<br> {<br> if(tagkey[i]==pidtag[i])<br> flag++;<br> }<br> if(flag==9)<br> {<br> pid=tagvalue;
<br> flag=0;<br> }<br> else<br> flag=0;<br> }//if ends here<br> itr++;<br> }//while ends here<br>}<br>----------<br><br>I would really appreciate if you could guide me as to what is going wrong here. Where is that memory leak and how do I fix it?
<br>Please help.<br><br>Thanks,<br>Ashish<br><br><div><span class="gmail_quote">On 8/27/07, <b class="gmail_sendername">Ashish Singh</b> <<a href="mailto:mrasingh@gmail.com">mrasingh@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi Luis,<br><br>Thanks for replying.I am using ITK- 3.2.0.<br><br>How do I modify this code without having to create reader and GDCMImageIO at every iteration? Maybe that is what is creating problem here. <br>I am going to run the application with the' header processing part' suppressed and will let you know exactly what happens. In the meantime, if you can tell me the modifications for using single reader and GDCMImageIO for all images, I could try that out too.
<br><br>Thanks,<br><span class="sg">Ashish</span><div><span class="e" id="q_114a82dad7d4b6e6_2"><br><br><div><span class="gmail_quote">On 8/27/07, <b class="gmail_sendername">Luis Ibanez</b> <<a href="mailto:luis.ibanez@kitware.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
luis.ibanez@kitware.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>Hi Ashish,<br><br>What version of ITK are you using ?<br><br> This looks like a memory leak...<br><br>Note that you really don't have to create<br>the reader an the GDCMImage IO at every<br>iteration of the loop. That being said,
<br>your code is still a valid construction.<br><br>Do you get the same error if you suppress<br>the code that is "oprocessing information from<br>header of each image" ?<br><br>It may be that that section of code contains
<br>a memory leak...<br><br><br> Please let us know<br><br><br> Thanks<br><br><br> Luis<br><br><br>--------------------<br>Ashish Singh wrote:<br>> Hi,<br>><br>> I have written an application to read and process dicom header
<br>> information. My application runs fine for small number of images but<br>> gives an error when it reaches about 70,000 images(the number varies<br>> each time).<br>> The error that I get is the following:
<br>> ---------------<br>> itk::ExceptionObject <01C5AC80><br>> Location: "unsigned char *_thiscall itk::ImportImageContainer<unsigned<br>> long,unsigned char>::AllocateElements<unsigned long> const"
<br>> File:<br>> c:\myinstalls\insighttoolkit-3.2.0\code\common\itkImportImageContainer.txx<br>><br>> Line: 188<br>> Description: Failed to allocate memory for image.<br>> ---------------<br>><br>> The images don't belong to a single
series.The application is running on<br>> windows XP Pro x64 platform. The relevant portion of the code looks like<br>> this -<br>> --------<br>> const unsigned int InputDimension =3;<br>> typedef unsigned char InputPixelType;
<br>> typedef itk::Image< InputPixelType, InputDimension > InputImageType;<br>> typedef itk::ImageFileReader< InputImageType > ReaderType;<br>> typedef itk::GDCMImageIO ImageIOType;<br>><br>> unsigned long fni;
<br>> for(fni=0;fni<250000;fni++)<br>> {<br>><br>> ReaderType::Pointer reader2 = ReaderType::New();<br>><br>> ImageIOType::Pointer gdcmImageIO2 = ImageIOType::New();<br>><br>> [set filename for reader2]
<br>> //fname = this->directory->absoluteFilePath(this->files[fni]);<br>> //reader2->SetFileName(std::string( fname.toAscii()));<br>><br>> reader2->SetImageIO(gdcmImageIO2);<br>> try
<br>> {<br>> reader2->Update();<br>> }<br>> catch (itk::ExceptionObject & e)<br>> {<br>> std::cerr << "exception in file reader " << std::endl;
<br>> std::cerr << e << std::endl;<br>> return EXIT_FAILURE;<br>> }<br>><br>> [ code for processing information from header of each image here]<br>><br>> //reader2->Delete();//not implemented
<br>> //gdcmImageIO2->Delete();//not implemented<br>><br>> }<br>> ----------<br>> I cannot call a delete inside the 'for' loop. It gives me an error<br>> saying that an error has occured and do you want to send information to
<br>> Microsoft?<br>> I also did some reading in ITK software guide, where it says that a<br>> smart pointer takes care of delete by itself. I also tried Register(),<br>> UnRegister(), ReleaseDataFlagOn().None of these work.
<br>> Can anyone please tell me what is going wrong here and how to fix it?<br>> How can I release the memory for the reader? Is there a simpler way to<br>> do this?<br>> I will really appreciate if someone can help me with this.
<br>><br>> Thanks,<br>> Ashish<br>><br>><br>> ------------------------------------------------------------------------<br>><br>> _______________________________________________<br>> Insight-users mailing list
<br>> <a href="mailto:Insight-users@itk.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Insight-users@itk.org</a><br>> <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
http://www.itk.org/mailman/listinfo/insight-users</a><br></blockquote></div><br>
</span></div></blockquote></div><br>