Memory problem when deleting objects in TFile/TDirectory

From: Pierre-Luc Drouin <pldrouin_at_physics.carleton.ca>
Date: Thu, 10 Nov 2005 13:06:33 -0500


Hi,

I have a TDirectory in which I create different objects that I delete once I am done using them. The objects are created and deleted in a loop. The problem is that ROOT takes more and more memory with iterations, even if I delete all TObject and TKey after each iteration. Here is a simple program that reproduces the problem.

int main(int nargs, char* args[])
{
  for (Int_t i=0; i<1000000; i++) {
    TDirectory *newdir=gDirectory->mkdir("testdir");     gDirectory->RecursiveRemove(newdir);     gDirectory->Delete("testdir;1");
  }
}

The memory used by this simple program increases at a rate of about 100 MB/s on my laptop until the memory is filled and I get a the following error:
terminate called after throwing an instance of 'std::bad_alloc'   what(): St9bad_alloc

What can I do to correctly clean the directory and ROOT memory? In the real code I am using I have sub-directories in what is equivalent to the "testdir" directory of the simple program. That is why I use TDirectory::RecursiveRemove to delete "newdir" and everything in its subdirectories.

Thank you!

Pierre-Luc Drouin Received on Thu Nov 10 2005 - 19:06:53 MET

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:13 MET