Deleting objects from " gObjectTable->Print();&quot

Dear Rooters,
My script works fine if the number of input files are small (say 2). If the number of files increases to ten, then it ends correctly. But, it take lot of time to exit from the root prompt. Then I would have to kill the process using the command “kill -9 pid”. I also printed the list of object on heap when the script ends. I found that the objects TH1F and TH2F consume 1.2 and 0.3 MB. It may be the reason behind the lot of time to exit from the root prompt. I would like to delete these objects from the heap. I found that it gives me zero number of key when I try to get “TIter next(gDirectory->GetListOfKeys());” Could you please let me know how should I delete the histograms in the mentioned case ?

I am attaching the script and root file. Please let me know if you need more information.

Many Thanks,
Manoj
Lambda1600Pt018.root (547 KB)
Signal.C (14.4 KB)

Hi,

I can not reproduce the slow down you mention (possibly because I did not find the right to move from 1 to 10 files).

However note that once you have written the histogram to the file (and if you no longer need to use it) you can delete it. So one option is simply to
dovoid JoinHisto(TString hname){ TString had = hname + "h"; TH1F* histoHad = Addition(had); delete histoHad; }

Also you have several memory leaks when you use the following pattern:

[code] TH2F* TwoDH[nPtHat];

for (int i =0; i < nPtHat; ++i)
	TwoDH[i] =  new TH2F();


TwoDH[counter] = (TH2F*)f[counter]->Get(hname)->Clone(hname + buffer);

delete [] TwoDH; [/code]
When you do TwoDH[counter] = …; you are losing the address of the TH2F you created with TwoDH[i] = new TH2F(); and hence this (useless) histogram is leaked. Instead you should simply do: for (int i =0; i < nPtHat; ++i) TwoDH[i] = 0; Next when you do delete [] TwoDH;this does only one histogram (and even those that wrongly). This delete would be correctly if and only if you add declared and intialize TwoDH as follow:TH2F *TwoDH = new TH2F[some_number];So instead you need to use: for (int i =0; i < nPtHat; ++i) delete TwoDH[i];

Cheers,
Philippe.

Hi Phillipe,
Thanks ! I followed the steps as mentioned by you. I found that the size of TH1F object grows to 12 MB and it takes couple of minutes to exit from the root prompt for ten input files. Is it possible to delete this object from the heap ?

Thanks,
Manoj

[quote]I followed the steps as mentioned by you[/quote]So it looks like you need to apply the same advise to more part of your code with similar patterns (i.e. go though you code and make sure to call delete for each and every of the histogram you create either via new or via Clone after you have written them to disk if you need to).

Cheers,
Philippe.

Hi Phillipe,
Thanks ! I followed the steps as mentioned by you. I found that the size of TH1F object grows to 12 MB and it takes couple of minutes to exit from the root prompt for ten input files. Is it possible to delete this object from the heap ?

Thanks,
Manoj

[quote]Is it possible to delete this object from the heap ? [/quote]Yes … call delete once for every new and Clone

Philippe