TF1 and memory leak

Hi Rooters,
I have a program that loops over the tree entries (~ millions) and applies some selections. One of these selection is the following:

if(!isPassed(energy, p1))
 continue;

where the function is defined as follows:


bool isPassed(Double_t en, Double_t P1)
{
   bool ret = false;
  TF1 * f_low = new TF1("f_low","[0]/x+[1]",0., 300.);
   f_low->SetParameters(2.64450e+07, 4.66029e+02);
   if (P1 > f_low->Eval(en) )
      ret = true;
  delete f_low;
  return ret;
}

I used bsub to submit the job and I got the following error:
TERM_MEMLIMIT: job killed after reaching LSF memory usage limit.
Exited with exit code 137.

As soon as I comment the line where the function is called, the program ends correctly. I don’t understand where the leak is and how to fix it.
Thanks for any help!


ROOT Version: 6.08/06
Platform: x86_64 GNU/Linux
Compiler: g++ (GCC) 8.3.0

Hi,
do you absolutely need to have

TF1 * f_low = new TF1("f_low","[0]/x+[1]",0., 300.);

inside the loop? It doesn’t look like it’s changing from iteration to iteration, maybe you can move it out? If not, maybe you can allocate memory for your TF1 in a stack and not in a heap?

You are right, thanks!
Writing the code in the following way seems to work:

TF1 f_low("f_low","[0]/x+[1]",0., 300.);

int main()
{
...
if(!isPassed(energy, p1))
 continue;
...
}

bool isPassed(Double_t en, Double_t P1)
{
   bool ret = false;
   f_low.SetParameters(2.64450e+07, 4.66029e+02);
   if (P1 > f_low.Eval(en) )
      ret = true;
  return ret;
}

However, I don’t understand what causes the leak if the memory is correctly deallocated with the delete operation.

@Axel I don’t know if this has ever been taken care of:

The following is not related to your problem, but you can also move the

f_low.SetParameters(2.64450e+07, 4.66029e+02);

outside of the loop, and the isPassed(...) will look much cleaner:

bool isPassed(Double_t en, Double_t P1)
{
  return (P1 > f_low.Eval(en))?true:false;
}

Actually, you won’t even need this function: the cut is simply

if (!(p1 > f_low.Eval(energy)))
  continue;

In fact, you don’t even need your TF1 object:

if (p1 < 2.64450e+07/energy + 4.66029e+02)
  continue;
1 Like

It looks like both leaks have disappear. It has been removed 9 months ago in TFormula::HandleParamRanges(TString &formula) and thus is not present anymore in ROOT 6.18.

And, the memory issue in TFile::GetStreamerInfoListImpl(bool lookupSICache) has been adressed 2 years ago and is not present anymore in ROOT 6.16.

1 Like

So they may be present in the original author’s:
ROOT Version: 6.08/06

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.