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>Ashish<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">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">Insight-users@itk.org</a><br>&gt; <a href="http://www.itk.org/mailman/listinfo/insight-users">http://www.itk.org/mailman/listinfo/insight-users</a><br></blockquote></div><br>