Big memory leak using ROOT/RooFit

Hi all,
I need some experts help to understand the output of valgrind and try to
fix some memory leaks.
Currently I’m using an application that uses roofit libraries (ROOT) to
perform a CP fit. The executable is currently showing a big memory leak
problem: when trying to analyze O(10k)events I end up with more than 3GB
of swap memory and my job crashes.

I wanted to understand the source of this leak (if the fault is mine and I
can fix something or if I need to file a bug report), and I’ve used
valgrind to run a job on few events…

I’m appending below some error messages I see.
I’d like advice on how to understand those errors:
are due to a bad implementation of my executable or should I ask
(ROOT RooFit) developers about them?

The full log is attached…
Any help on how to deal with so many problems [and how to spot the most
serious ones] will be greatly appreciated.

Thanks and cheers,
alessio
PS I’m going to cc this email also to ROOT forums…

The first big problem I see is related to

==6619==
==6619== 883,479 bytes in 22,951 blocks are possibly lost in loss record
108 of 313
==6619== at 0x4005835: operator new
(vg_replace_malloc.c:195)
==6619== by 0x41B6E88: TStringRef::GetRep(int, int) (in
/home/Packages/root/lib/libCore.so)
==6619== by 0x41B75BC: TString::TString(char const*) (in
/home/Packages/root/lib/libCore.so)
==6619== by 0x41F28B7: TClassTable::Add(char const*, short,
std::type_info const&, void ()(), int) (in
/home/Packages/root/lib/libCore.so)
==6619== by 0x41F2965: ROOT::AddClass(char const
, short,
std::type_info const&, void ()(), int) (in
/home/Packages/root/lib/libCore.so)
==6619== by 0x422F4DB: ROOT::TDefaultInitBehavior::Register(char
const
, short, std::type_info const&, void ()(), int) const (in
/home/Packages/root/lib/libCore.so)
==6619== by 0x422E630: ROOT::TGenericClassInfo::Init(int) (in
/home/Packages/root/lib/libCore.so)
==6619== by 0x422EAF5: ROOT::TGenericClassInfo::TGenericClassInfo(char
const
, char const*, int, std::type_info const&, ROOT::TInitBehavior
const*, void*, void ()(), TVirtualIsAProxy, int, int) (in
/home/Packages/root/lib/libCore.so)
==6619== by 0x671D9D7:
ROOT::GenerateInitInstanceLocal(ROOT::Math::Cartesian3D const*)
(in /home/Packages/root/lib/libMathCore.so)
==6619== by 0x6721C0E: __static_initialization_and_destruction_0(int,
int) (in /home/Packages/root/lib/libMathCore.so)
==6619== by 0x6721D90:
_GLOBAL__I__ZN4ROOT53ROOTcLcLMathcLcLCartesian3DlEDouble32_tgR_ShowMembersEPvR16TMemberInspectorPc
(in /home/Packages/root/lib/libMathCore.so)
==6619== by 0x6765B65: (within /home/Packages/root/lib/libMathCore.so)

The second one to

==6619== 624,312 bytes in 78 blocks are possibly lost in loss record 308
of 313
==6619== at 0x4005835: operator new
(vg_replace_malloc.c:195)
==6619== by 0x4CFD4BA: TFormula::Compile(char const*) (in
/home/Packages/root/lib/libHist.so)
==6619== by 0x6005B82: RooFormula::RooFormula(char const*, char const*,
RooArgList const&) (in /home/Packages/root/lib/libRooFit.so)
==6619== by 0x6007657: RooFormulaVar::formula() const (in
/home/Packages/root/lib/libRooFit.so)
==6619== by 0x60077D0: RooFormulaVar::evaluate() const (in
/home/Packages/root/lib/libRooFit.so)
==6619== by 0x5F9BE51: RooAbsReal::traceEval(RooArgSet const*) const
(in /home/Packages/root/lib/libRooFit.so)
==6619== by 0x5F9BF6D: RooAbsReal::getVal(RooArgSet const*) const (in
/home/Packages/root/lib/libRooFit.so)
==6619== by 0x5FFFB5C: RooExtendPdf::expectedEvents(RooArgSet const*)
const (in /home/Packages/root/lib/libRooFit.so)
==6619== by 0x6062B19: RooProdPdf::expectedEvents(RooArgSet const*)
const (in /home/Packages/root/lib/libRooFit.so)
==6619== by 0x6062B19: RooProdPdf::expectedEvents(RooArgSet const*)
const (in /home/Packages/root/lib/libRooFit.so)
==6619== by 0x5FB548A: RooAddPdf::expectedEvents(RooArgSet const*)
const (in /home/Packages/root/lib/libRooFit.so)
==6619== by 0x5FB548A: RooAddPdf::expectedEvents(RooArgSet const*)
const (in /home/Packages/root/lib/libRooFit.so)
MemoryLeak.txt (190 KB)

  1. Which version of ROOT do you use? (I didn’t notice it in your message)
  2. Can you try your code with CVS head version?
  3. If you can use CVS, and you still have leaks - can you, please, give the shortest example of code reproducing your problem?

I do remember some problems with memory leaks in ROOT’s TFormula but it was fixed in some version.

BTW I think you need valgrind only if you have something really complex - for example, big, complex third-party library which you cannot check. But first of all you must be sure, that your own programm does not leak, and it’s often easy to do without any special checkers.

I have mailed your problem to Wouter Verkerke. I hope that he will
give an answer soon.

Rene

Hi Alessio,

Is the the same leak as in your recent posting?

I see nothing suspect from the RooFit side
in these valgrind dumps…

Wouter

Dear all,
the leak i’m talking about in this posting is not the one mentioned before in a different posting (that eats that much SWAP memory). This is a leak detected by vagrind that has been traced back to TFormula.
I’m using version 5.13/06. I will try with 5.14 or newer and I’ll let you know if the leak is still there!

Thanks for helping.
Alessio