Memory leaks when doing repeated fits, either with fitTo
or by calling RooMinimizer::migrad
interactively. This becomes a major problem for applications that must do many fits. Reproducer below.
Reproducer:
import ROOT as r
# create a variable
x = r.RooRealVar("x", "x", 0, 10)
# create a pdf
gm = r.RooRealVar("gm", "gm", 5, 0, 10)
pdf = r.RooGaussian("g", "g", x, gm, r.RooFit.RooConst(1))
# generate data
data = pdf.generate({x})
# fit it many times
print("Starting loop")
r.RooMsgService.instance().setGlobalKillBelow(r.RooFit.FATAL)
while True:
pdf.fitTo(data, PrintLevel=-1)
Here is the resulting memory leak (made with psrecord):
test.pdf (13.6 KB)
This is also the case using Minuit interactively:
import ROOT as r
# create a variable
x = r.RooRealVar("x", "x", 0, 10)
# create a pdf
gm = r.RooRealVar("gm", "gm", 5, 0, 10)
pdf = r.RooGaussian("g", "g", x, gm, r.RooFit.RooConst(1))
# generate data
data = pdf.generate({x})
# create minimizer
nll = pdf.createNLL(data)
m = r.RooMinimizer(nll)
m.setPrintLevel(-1)
# fit it many times
print("Starting loop")
r.RooMsgService.instance().setGlobalKillBelow(r.RooFit.FATAL)
while True:
m.migrad()
Resulting in test_with_nll.pdf (13.3 KB).
The memory leak disappears if the minimizer is recreated:
import ROOT as r
# create a variable
x = r.RooRealVar("x", "x", 0, 10)
# create a pdf
gm = r.RooRealVar("gm", "gm", 5, 0, 10)
pdf = r.RooGaussian("g", "g", x, gm, r.RooFit.RooConst(1))
# generate data
data = pdf.generate({x})
# create nll
nll = pdf.createNLL(data)
# in a loop, create minimizer and fit it
print("Starting loop")
r.RooMsgService.instance().setGlobalKillBelow(r.RooFit.FATAL)
while True:
m = r.RooMinimizer(nll)
m.setPrintLevel(-1)
m.migrad()
test_with_nll_recreate.pdf (14.6 KB)