Memory leaking in TGraph::Fit

Dear experts,

when running my code through valgrind, I receive (among others) the following leak information:

==30431== 895,176 (580,800 direct, 314,376 indirect) bytes in 1,320 blocks are definitely lost in loss record 19,634 of 19,696 ==30431== at 0x4A085FC: operator new(unsigned long) (vg_replace_malloc.c:298) ==30431== by 0xF2919D8: TStorage::ObjectAlloc(unsigned long) (in /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.04.12-x86_64-slc6-gcc49-opt/lib/libCore.so) ==30431== by 0x2920783B: TLinearMinimizer::SetFunction(ROOT::Math::IGradientFunctionMultiDim const&) (in /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.04.12-x86_64-slc6-gcc49-opt/lib/libMinuit.so) ==30431== by 0xE70FA97: ROOT::Fit::Fitter::DoInitMinimizer() (in /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.04.12-x86_64-slc6-gcc49-opt/lib/libMathCore.so) ==30431== by 0xE711061: ROOT::Fit::Fitter::DoMinimization(ROOT::Math::IBaseFunctionMultiDim const&, ROOT::Math::IBaseFunctionMultiDim const*) (in /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.04.12-x86_64-slc6-gcc49-opt/lib/libMathCore.so) ==30431== by 0xE711A9B: ROOT::Fit::Fitter::DoLeastSquareFit() (in /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.04.12-x86_64-slc6-gcc49-opt/lib/libMathCore.so) ==30431== by 0x1DF0A7A6: TFitResultPtr HFit::Fit<TGraph>(TGraph*, TF1*, Foption_t&, ROOT::Math::MinimizerOptions const&, char const*, ROOT::Fit::DataRange&) (in /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.04.12-x86_64-slc6-gcc49-opt/lib/libHist.so) ==30431== by 0x1DEFEEE9: ROOT::Fit::FitObject(TGraph*, TF1*, Foption_t&, ROOT::Math::MinimizerOptions const&, char const*, ROOT::Fit::DataRange&) (in /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.04.12-x86_64-slc6-gcc49-opt/lib/libHist.so) ==30431== by 0x1DFB3BBF: TGraph::Fit(TF1*, char const*, char const*, double, double) (in /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.04.12-x86_64-slc6-gcc49-opt/lib/libHist.so) ==30431== by 0x1DFB1E84: TGraph::Fit(char const*, char const*, char const*, double, double) (in /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.04.12-x86_64-slc6-gcc49-opt/lib/libHist.so)

Unfortunately, I’ve not been able to reproduce this particular leak with an MWE, but conceptually, what I’m doing is this:

[code] TDirectory* d = new TDirectory(“mydir”,“My Dir”);
TGraphErrors* g = new TGraphErrors();
g->SetName(“mygraph”);

g->SetPoint(0,1,1);
g->SetPointError(0,0.1,0);

g->SetPoint(1,2,2.1);
g->SetPointError(1,0.2,0);

g->SetPoint(2,3,2.9);
g->SetPointError(2,0.2,0);

g->Fit(“pol1”,“Q”,"",0,2);
d->Add(g);
TCanvas* c = new TCanvas(“mycanvas”);
g->Draw();
c->SaveAs(“myplot.pdf”);
d->Add©;
d->DeleteAll();[/code]

Which object do I need to delete in order to avoid this leak?

To me, this looks as if the fitting function and/or the minimizer not properly deleted. I’m using ROOT 6.04/12.

HI,

This has been fixed in the ROOT master version. You can use the option “G” (avoid using linear fitter) as a workaround.
See similar report TGraphError Fit memory leak

Best Regards

Lorenzo