TList *files = dir.GetListOfFiles(); Error

I am looping over 1300 directories using the attached function.
This is done by reading a FileList.txt that contains the directories.

The strange thing is that I can loop over directory 1-990 Then it
stops working. It simply does not go beyond line if(files){

Meaning it something related to the line TList *files = dir.GetListOfFiles();

If on the other hand I start a new list that begins with
directory 990 it works fine. which is my quick fix for this.

Any thoughts to what could be the reason this is?

[code]TString list_files(const char *dirname, const char *ext,TString &fname1)
{
TSystemDirectory dir(dirname, dirname);
cout << dirname <<" " << ext << endl;
TList *files = dir.GetListOfFiles();
/////
if(files) {
cout << "listfile is used: " << endl;
TSystemFile file;
TIter next(files);
TString fname;
while ((file=(TSystemFile
)next())) {
fname = file->GetName();
if (!file->IsDirectory() && fname.EndsWith(ext)) {
fname1 =fname;
cout <<“here:”<< fname1 << endl;
}
}
}
//files->Delete();
return fname1;
}

void main() {
//loop over directories using a while loop
while(true) {
open the filelist.txt
list_files(eventDir.Data(),“f.root”,rootFilename);
}
}[/code]

Hi,

Where you have: //files->Delete();you should have delete files;otherwise you have a potentially large memory leak.

Cheers,
Philippe.

I tried that at one point while debugging and that did not work.
Any leads as to where the potential memory leak might be.

Many thanks for your help…

How did it not work (i.e. the delete is necessary).

Philippe.

If I add delete it gets stuck at 993 instead 990 but still stuck.
same error it reads the directory name “dirname” just fine. But it does not
get beyond if(files). This is why I think it is TList *files related memory leak of come sort.
Not sure how to fix that beyond delete. Any ideas are very welcome.

Thanks again Phillipe.

I think we need a more “complete” source code than what you show in the first post here.

BTW. Maybe you are opening too many files simultaneously. Quite often the “soft limit” is 1024, so try to increase it to 2048 using (for bash) “ulimit -S -n 2048” or (for tcsh) “limit descriptors 2048” (and then in the same terminal window / shell try to run your application again).

Many thanks Pepe Le Pew for your help. The ulimit suggestion worked. That was the problem.
All the best…