# Too many open files

**URL:** <https://root-forum.cern.ch/t/too-many-open-files/9237>\
**Category:** ROOT\
**Created:** [November 16, 2009, 11:23am UTC](https://root-forum.cern.ch/t/too-many-open-files/9237 "2009-11-16T11:23:30Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![karineklund](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/f07891/32.png) [@karineklund](https://root-forum.cern.ch/u/karineklund)\
**Post date:** [November 16, 2009, 11:23am UTC](https://root-forum.cern.ch/t/too-many-open-files/9237/1 "2009-11-16T11:23:30Z")

</div>

Dear Rooters,

I am writing a macro where I wish to read histograms from 1000 files and add them together. I open each file at the time in a loop using:

TFile \*myFile = new TFile();  
myFile-\>Open(fileName,“read”);

From the file I copy two histograms (I don’t think this is relevant but) using the ROOT feature that whenever a file is opened you automatically enter this file:

h\_Ptmp = new TH1F(\*h\_primaryElectronFluenceSpectrum);  
h\_Stmp = new TH1F(\*h\_scatterElectronFluenceSpectrum);

Finally I close the file and delete the myFile object (at the end of the loop)

myFile-\>Close();  
delete myFile;

However, after some 938 files ROOT crashes telling me that there are too many open files. How can this be? I only open one file at the time and I also close it afterwards? I did some manual testing with cint and also there experienced that even if a TFile is close and the pointer deleted the command “.ls” will still print what is inside the file.

Help would be most appreciated, my Ph.D depends on this merge 😉

Cheers,  
Karin

---

_[View the full topic](https://root-forum.cern.ch/t/too-many-open-files/9237)._
