Problem with closing files


I have a problem with closing the files. Probably there is some trivial error…

I have an array with 71 files. I define “infile” outside the loop. Although I use command “Close” the files are still open which was checked with gROOT->GetListOfFiles()->Last()->GetName() and gROOT->GetListOfFiles()->At(0)->GetName()

The program crashes with the following message
SysError in TFile::TFile: file C14R2_FINAL_RootFiles/GoodPosition_ana_C14R2_vert_b2_zP3000_all.root can not be opened for reading (Too many open files)
when around 947 files are open.

Here is a part of my code:

TFile * infile = new TFile();

for (Int_t i=0; i<71; i++) {


cout << "LAST FILE = " << gROOT->GetListOfFiles()->Last()->GetName() << endl;
cout << "FIRST FILE = " << gROOT->GetListOfFiles()->At(0)->GetName() << endl;

cout<<"Filename = "<<FileName[i]<<endl;

// … here I take data from histograms stored in the files …



I have also tried with infile->Close(“R”) and infile->Delete() but they don’t work…

Could you please advise me how to solve it?

Best regards,
Agnieszka Priebe

[url]Problem with closing files