Hi Luis,<br><br>I ran the code suppressing header processing part and I don&#39;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&lt; InputPixelType, InputDimension &gt; InputImageType;<br>typedef itk::ImageFileReader&lt; InputImageType &gt; ReaderType;<br>typedef itk::GDCMImageIO ImageIOType;
<br>typedef itk::MetaDataDictionary&nbsp;&nbsp; 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&lt;250000;fni++)<br>{<br><br>&nbsp;&nbsp;&nbsp; ReaderType::Pointer reader2 = ReaderType::New();<br><br>&nbsp;&nbsp;&nbsp; ImageIOType::Pointer gdcmImageIO2 = ImageIOType::New();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; [set filename for reader2]<br>&nbsp;&nbsp;&nbsp; //fname = this-&gt;directory-&gt;absoluteFilePath(this-&gt;files[fni]);
<br>&nbsp;&nbsp;&nbsp; //reader2-&gt;SetFileName(std::string( fname.toAscii()));<br><br>&nbsp;&nbsp;&nbsp; reader2-&gt;SetImageIO(gdcmImageIO2);<br>&nbsp;&nbsp;&nbsp; try<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reader2-&gt;Update();<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; catch (itk::ExceptionObject &amp; e)<br>
&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; &quot;exception in file reader &quot; &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; e &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return EXIT_FAILURE;<br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; [ code for processing information from header of each image from here]
<br><br>&nbsp;&nbsp;&nbsp; this-&gt;image=reader2-&gt;GetOutput();<br>&nbsp;&nbsp;&nbsp; this-&gt;dictionary=this-&gt;image-&gt;GetMetaDataDictionary();<br>&nbsp;&nbsp;&nbsp; this-&gt;readfiles();<br>&nbsp;&nbsp;&nbsp; [ code for processing information from header of each image till here]
<br><br>&nbsp;&nbsp;&nbsp; //reader2-&gt;Delete();//not implemented<br>&nbsp;&nbsp;&nbsp; //gdcmImageIO2-&gt;Delete();//not implemented<br><br>}<br><br>readfiles()<br>{<br>&nbsp;&nbsp; int flag;<br>&nbsp;&nbsp; string pid,pidtag;<br>&nbsp;&nbsp; pidtag=&quot;0010|0020&quot;;<br>&nbsp;&nbsp; DictionaryType::ConstIterator itr = this-&gt;
dictionary.Begin();<br>&nbsp;&nbsp; DictionaryType::ConstIterator end = this-&gt;dictionary.End();<br>&nbsp;&nbsp; while( itr != end )<br>&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp; itk::MetaDataObjectBase::Pointer&nbsp; entry = itr-&gt;second;<br>&nbsp;&nbsp;&nbsp;&nbsp; MetaDataStringType::Pointer entryvalue = dynamic_cast&lt;MetaDataStringType *&gt;( 
entry.GetPointer() ) ;<br>&nbsp;&nbsp;&nbsp;&nbsp; if( entryvalue )<br>&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::string tagkey&nbsp;&nbsp; = itr-&gt;first;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::string labelId;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bool found =&nbsp; itk::GDCMImageIO::GetLabelFromTag( tagkey, labelId );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::string tagvalue = entryvalue-&gt;GetMetaDataObjectValue();
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flag=0;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //get patient Id in a string<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(i=0;i&lt;9;i++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(tagkey[i]==pidtag[i])<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flag++;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(flag==9)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pid=tagvalue;
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flag=0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; flag=0;<br>&nbsp;&nbsp;&nbsp;&nbsp; }//if ends here<br>&nbsp;&nbsp; itr++;<br>&nbsp; }//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> &lt;<a href="mailto:mrasingh@gmail.com">mrasingh@gmail.com</a>&gt; 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&#39; header processing part&#39; 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> &lt;<a href="mailto:luis.ibanez@kitware.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
luis.ibanez@kitware.com</a>&gt; 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>&nbsp;&nbsp; This looks like a memory leak...<br><br>Note that you really don&#39;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 &quot;oprocessing information from<br>header of each image&quot; ?<br><br>It may be that that section of code contains
<br>a memory leak...<br><br><br>&nbsp;&nbsp; Please let us know<br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thanks<br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Luis<br><br><br>--------------------<br>Ashish Singh wrote:<br>&gt; Hi,<br>&gt;<br>&gt; I have written an application to read and process dicom header
<br>&gt; information. My application runs fine for small number of images but<br>&gt; gives an error when it reaches about 70,000 images(the number varies<br>&gt; each time).<br>&gt; The error that I get is the following:
<br>&gt; ---------------<br>&gt; itk::ExceptionObject &lt;01C5AC80&gt;<br>&gt; Location: &quot;unsigned char *_thiscall itk::ImportImageContainer&lt;unsigned<br>&gt; long,unsigned char&gt;::AllocateElements&lt;unsigned long&gt; const&quot;
<br>&gt; File:<br>&gt; c:\myinstalls\insighttoolkit-3.2.0\code\common\itkImportImageContainer.txx<br>&gt;<br>&gt; Line: 188<br>&gt; Description: Failed to allocate memory for image.<br>&gt; ---------------<br>&gt;<br>&gt; The images don&#39;t belong to a single 
series.The application is running on<br>&gt; windows XP Pro x64 platform. The relevant portion of the code looks like<br>&gt; this -<br>&gt; --------<br>&gt; const unsigned int InputDimension =3;<br>&gt; typedef unsigned char InputPixelType;
<br>&gt; typedef itk::Image&lt; InputPixelType, InputDimension &gt; InputImageType;<br>&gt; typedef itk::ImageFileReader&lt; InputImageType &gt; ReaderType;<br>&gt; typedef itk::GDCMImageIO ImageIOType;<br>&gt;<br>&gt; unsigned long fni;
<br>&gt; for(fni=0;fni&lt;250000;fni++)<br>&gt; {<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; ReaderType::Pointer reader2 = ReaderType::New();<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; ImageIOType::Pointer gdcmImageIO2 = ImageIOType::New();<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; [set filename for reader2]
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; //fname = this-&gt;directory-&gt;absoluteFilePath(this-&gt;files[fni]);<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; //reader2-&gt;SetFileName(std::string( fname.toAscii()));<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; reader2-&gt;SetImageIO(gdcmImageIO2);<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; try
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reader2-&gt;Update();<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; catch (itk::ExceptionObject &amp; e)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; &quot;exception in file reader &quot; &lt;&lt; std::endl;
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; e &lt;&lt; std::endl;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return EXIT_FAILURE;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; [ code for processing information from header of each image here]<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; //reader2-&gt;Delete();//not implemented
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; //gdcmImageIO2-&gt;Delete();//not implemented<br>&gt;<br>&gt; }<br>&gt; ----------<br>&gt; I cannot call a delete inside the &#39;for&#39; loop. It gives me an error<br>&gt; saying that an error has occured and do you want to send information to
<br>&gt; Microsoft?<br>&gt; I also did some reading in ITK software guide, where it says that a<br>&gt; smart pointer takes care of delete by itself. I also tried Register(),<br>&gt; UnRegister(), ReleaseDataFlagOn().None of these work.
<br>&gt; Can anyone please tell me what is going wrong here and how to fix it?<br>&gt; How can I release the memory for the reader? Is there a simpler way to<br>&gt; do this?<br>&gt; I will really appreciate if someone can help me with this.
<br>&gt;<br>&gt; Thanks,<br>&gt; Ashish<br>&gt;<br>&gt;<br>&gt; ------------------------------------------------------------------------<br>&gt;<br>&gt; _______________________________________________<br>&gt; Insight-users mailing list
<br>&gt; <a href="mailto:Insight-users@itk.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Insight-users@itk.org</a><br>&gt; <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>