Home | News | Documentation | Download

High memory usage when performing simulation and TTree filling

Hello:

First time using this forum! I’m having an issue, performing a simulation (creating random Double_t) and filling then into a TTree (with several Branches). However, I have to run the simulation many times to get some kind of statistics, and to do so I’m using a for loop over the other for loop of around 10^6 iterations.

Writing on a different file each repetition, memory usage keeps growing without stop, even when the simulation ends (I have to manually .q to free it), and I don’t know why. I tried some combinations of options, and none of them worked. I just need to write 2 TH2 and 1 TTree into the files; I have already linked them to the output file and Close() and deleted it, as you can see in the attached macro. The answers from another topics seem to have no better outcome. Probably it’s an easy issue that I couldn’t have found looking at the code, but I’m just a beginner with ROOT!

Hope you can help me, and thanks in advance!

Main macro: it’s here, i hope you don’t have to run it: ROOT macro - Pastebin.com


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.22/06
Platform: Ubuntu 20.04
Compiler: Pre-built version from web


Modify all your functions in the following way:

TGraphErrors *gsth1 = new TGraphErrors("./20Mg_mestura_530mbar.dat", "%lg %lg");
TSpline3 *RmmvsEMeV = new TSpline3("RmmvsEMeV", gsth1->GetX(), gsth1->GetY(), gsth1->GetN(), "b2,e2", 0., 0.);

Double_t myfunction(Double_t *x, Double_t */*par*/) {
  return RmmvsEMeV->Eval(x[0]);
}

Indeed now works pretty fine (even faster)! I guess I was missing the memory occupation of the pointers inside the functions every time i called them, right?

Thank you!