Help with Deleting tFolder from memory

Hi all,

I am trying to read a histogram out of a TFolder in a root file, and I repeat this process 5 times. I have provided a skeleton of what I do below.

What I am finding is that each time I add a new TFolder the memory usage goes up by about 400 Meg, so repeating this 6 times slows down the computer considerably, moreover repeating the routine, will cause a crash.

Is there a way to remove the tfolder’s memory allocation? Thanks for any and all help.

Ben

int play(){
for(int j = 0; j<2; j++){
switch(j){
case 0:
TFile f2 = new TFile("/home/bauerbac/yale/yframework/output/new/10Tev/zee2j_pdg11/all.root", “READ”);
if (!f2) cout << “there is no file” << endl;
f2->cd();
TFolder
fFolder1 = (TFolder*)f2 ->Get(“UC;1”); // get folder
fMetvsMass = (TH2F*) f2->Get(“UC/lljets/lljets_z_metvsmass”);
if(fMetvsMass) fMetvsMass->Draw();

  f2->Close("R");
  break;

case 1: 
  TFile *f3 = new TFile("/home/bauerbac/yale/yframework/output/new/10Tev/zee3j_pdg11/all.root", "READ");
  if (!f3) cout << "there is no file" << endl;
  f3->cd();
  TFolder* fFolder1 = (TFolder*)f3 ->Get("UC;1");  // get folder
  fMetvsMass = (TH2F*) fFolder1->FindObjectAny("lljets_z_metvsmass");
  f3->Close("R");

  break;
}

}
delete fFolder1;
return -1;
}

Hi,

The TFolder are not automatically attached to the file and hence are not deleted when you close the file. If you need to get rid of them, you need to delete them explicitly.

Cheers,
Philippe.

Thanks for your help Philippe.

If I just use delete fFolder1 this is not enough, how do I delete it explicitly from memory?

Thanks,
Ben

see: root.cern.ch/root/html/TFolder.h … r:SetOwner

Rene

Thanks for the suggestion Rene, I have tried this, and I see the memory continues to rise.

We need a concrete piece of code reproducing the problem and a data file.
Note that the SetOwner bit is read from the TFolder in the file.

Rene

I have attached a source code, and a data file as requested. The all.root file is a slimmed down version of the all.root I am calling in the routine. And I have changed the code such that it calls the same .root file twice. If you run the play() routine more than once you see the memory usage rise in top.

Thanks for your help!
Ben
skeleton.C (1.44 KB)
all.root (1.9 MB)

Hi all,
I have the same problems with deleting TFolders and rising memory.
I can not find the answer to the last Ben’s post.
With best wishes,
Vladimir