# ITKIOGDCM error with long dicom datasets

**URL:** <https://discourse.itk.org/t/itkiogdcm-error-with-long-dicom-datasets/6173>\
**Category:** Beginner Questions\
**Tags:** itk, dicom\
**Created:** [September 1, 2023, 9:21am UTC](https://discourse.itk.org/t/itkiogdcm-error-with-long-dicom-datasets/6173 "2023-09-01T09:21:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![arvequina](https://discourse.itk.org/user_avatar/discourse.itk.org/arvequina/32/3666_2.png) [@arvequina](https://discourse.itk.org/u/arvequina)\
**Post date:** [September 1, 2023, 9:21am UTC](https://discourse.itk.org/t/itkiogdcm-error-with-long-dicom-datasets/6173/1 "2023-09-01T09:21:20Z")

</div>

Hi! First thank you to all the contributors in here as it is always super useful. Probably this one is more indicated for the GDCM guru @mathieu.malaterre 😅

I ran into a problem using GDCM to read dicom files in windows 11.

> ITK version: 5.2.0  
> OS: windows 11

I am trying to read a DICOM folder, containing **270 dicom files**. For that I simply use an ITK image reader with IOGDCM registered.

```auto
// Define pixel and image types
typedef unsigned short PixelType;
typedef itk::Image<PixelType, 2> ImageType;
// Define image reader with GDCMImageIO
typedef itk::ImageFileReader<ImageType> ReaderType;   
ReaderType::Pointer reader = ReaderType::New();
// Create GDCMImageIO object and set it to the reader
typedef itk::GDCMImageIO ImageIOType;
ImageIOType::Pointer gdcmImageIO = ImageIOType::New();
reader->SetImageIO(gdcmImageIO);
reader->SetFileName(dicomData->filePath.toStdString());
// Read the DICOM image
try {
    reader->Update();
} catch (itk::ExceptionObject& ex) {
    std::cerr << "[ERROR] reading DICOM image: " << ex << std::endl;
    return;
}

```

This is done for each DICOM file.

When you read the folder once, everything goes fine but when you try to read it again, I get the following error:

```auto
itk::ExceptionObject (00000050A30F2060)
Location: "unknown" 
File: C:\Users\arveq\Documents\newb\src\ITK\Modules\IO\ImageBase\src\itkImageIOBase.cxx
Line: 649
Description: ITK ERROR: GDCMImageIO(00000215323B8490): Could not open file: C:/Users/arveq/Documents/newb/test_images/cs_3di_mc_flip25/116_tof_post.1.3.46.670589.11.71604.5.0.8232.2022013107454698394.186.dcm for reading.
Reason: Too many open files

```

Anyone has any clue about it? I did not find any info online and I tried to debug ITK’s code to find the origin of this _“Too many open files”_ but it is itksys generating it and it is a bit confusing. In theory there is a new Reader created for each frame so I do not understand why there would be _“Too many open files”_.

**Note:**  
On top of it, if I run the same code in macOS there is no issue at all. And the application runs much faster. My mac’s hardware is worse than my windows machine 😅

I have also tried:

- ITK v5.3.0, same problem.
- in macOS everything works fine.

I assume it is a bug but I might be doing something wrong.

Any help will be super welcomed! 😊

Thanks!

**UPDATE**  
It seems to be a bug in ITK not being able to close file descriptors properly, because if I set the limit of opened file descriptors the error does not happen again. I always assumed that ITK was managing that for you…am I missing something?
