Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RF] Fix some memory leaks in Python tutorials #16670

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/root-ci-config/buildconfig/ubuntu2410.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pythia8=OFF
tmva-cpu=OFF
2 changes: 2 additions & 0 deletions .github/workflows/root-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ jobs:
overrides: ["imt=Off", "LLVM_ENABLE_ASSERTIONS=On", "CMAKE_BUILD_TYPE=Debug"]
- image: ubuntu2404
overrides: ["LLVM_ENABLE_ASSERTIONS=On", "CMAKE_BUILD_TYPE=Debug"]
- image: ubuntu2410
overrides: ["LLVM_ENABLE_ASSERTIONS=On", "CMAKE_BUILD_TYPE=Debug"]
- image: debian125
overrides: ["LLVM_ENABLE_ASSERTIONS=On", "CMAKE_CXX_STANDARD=20"]
# Special builds
Expand Down
11 changes: 7 additions & 4 deletions bindings/pyroot/pythonizations/python/ROOT/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,20 @@ def cleanup():
if "libROOTPythonizations" in sys.modules:
backend = sys.modules["libROOTPythonizations"]

# Make sure all the objects regulated by PyROOT are deleted and their
# Python proxies are properly nonified.
backend.ClearProxiedObjects()

from ROOT import PyConfig

if PyConfig.ShutDown:
# Hard teardown: run part of the gROOT shutdown sequence.
# Running it here ensures that it is done before any ROOT libraries
# are off-loaded, with unspecified order of static object destruction.
backend.gROOT.EndOfProcessCleanups()
else:
# Make sure all the objects regulated by PyROOT are deleted and their
# Python proxies are properly nonified.
backend.ClearProxiedObjects()

del sys.modules["libROOTPythonizations"]



atexit.register(cleanup)
4 changes: 2 additions & 2 deletions interpreter/cling/tools/plugins/clad/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ ExternalProject_Add(
-DLLVM_DIR=${LLVM_BINARY_DIR}
-DCLANG_INCLUDE_DIRS=${CLANG_INCLUDE_DIRS}
${_clad_extra_cmake_args}
BUILD_COMMAND ${CMAKE_COMMAND} --build . ${EXTRA_BUILD_ARGS}
INSTALL_COMMAND ${CMAKE_COMMAND} --build . ${EXTRA_BUILD_ARGS} --target install
BUILD_COMMAND ${CMAKE_COMMAND} --build . ${EXTRA_BUILD_ARGS} -j 1
INSTALL_COMMAND ${CMAKE_COMMAND} --build . ${EXTRA_BUILD_ARGS} -j 1 --target install
BUILD_BYPRODUCTS ${CLAD_BYPRODUCTS}
${_clad_extra_settings}
# We need the target clangBasic to be built before building clad. However, we
Expand Down
2 changes: 1 addition & 1 deletion tutorials/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ if(ROOT_pyroot_FOUND)
tutorial-pyroot-na49view-py
tutorial-pyroot-h1ReadAndDraw-py
tutorial-pyroot-ntuple1-py)
set(pyroot-fit1-depends tutorial-pyroot-fillrandom-py)
set(pyroot-fit1-depends tutorial-hist-fillrandom-py)
set(pyroot-na49view-depends tutorial-pyroot-geometry-py)
set(roofit-rf503_wspaceread-depends tutorial-roofit-rf502_wspacewrite-py)
set(roofit-rf618_mixture_models-depends tutorial-dataframe-df106_HiggsToFourLeptons-py)
Expand Down
2 changes: 2 additions & 0 deletions tutorials/fit/combinedFit.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ def __call__(self, par):
hSB = ROOT.TH1D("hSB", "histo S+B", 100, 0, 100)

fB = ROOT.TF1("fB", "expo", 0, 100)
ROOT.SetOwnership(fB, False)
fB.SetParameters(1, -0.05)
hB.FillRandom("fB")

fS = ROOT.TF1("fS", "gaus", 0, 100)
ROOT.SetOwnership(fS, False)
fS.SetParameters(1, 30, 5)

hSB.FillRandom("fB", 2000)
Expand Down
1 change: 1 addition & 0 deletions tutorials/fit/fitConvolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
f_conv.SetRange(-1.0, 6.0)
f_conv.SetNofPointsFFT(1000)
f = ROOT.TF1("f", f_conv, 0.0, 5.0, f_conv.GetNpar())
ROOT.SetOwnership(f, False)
f.SetParameters(1.0, -0.3, 0.0, 1.0)

c1 = ROOT.TCanvas("c1", "c1", 800, 1000)
Expand Down
1 change: 1 addition & 0 deletions tutorials/fit/fitNormSum.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
# 4) :

f_sum = ROOT.TF1("fsum", fnorm_exp_cb, -5.0, 5.0, fnorm_exp_cb.GetNpar())
ROOT.SetOwnership(f_sum, False)

# III.:
parameter_values = fnorm_exp_cb.GetParameters()
Expand Down
2 changes: 2 additions & 0 deletions tutorials/hist/fillrandom.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
ROOT.gBenchmark.Start("fillrandom")

form1 = ROOT.TFormula("form1","abs(sin(x)/x)")
ROOT.SetOwnership(form1, False)
sqroot = ROOT.TF1("sqroot","x*gaus(0) + [3]*form1",0,10)
ROOT.SetOwnership(sqroot, False)
sqroot.SetParameters(10,4,1,20)
pad1.SetGridx()
pad1.SetGridy()
Expand Down
1 change: 1 addition & 0 deletions tutorials/hist/ratioplot1.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
h1 = ROOT.TH1D("h1", "h1", 50, 0, 10)
h2 = ROOT.TH1D("h2", "h2", 50, 0, 10)
f1 = ROOT.TF1("f1", "exp(- x/[0] )")
ROOT.SetOwnership(f1, False)
f1.SetParameter(0,3)

h1.FillRandom("f1",1900)
Expand Down
5 changes: 5 additions & 0 deletions tutorials/math/Bessel.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
##
## \author Juan Fernando Jaramillo Botero

import ROOT
from ROOT import TCanvas, TF1, gSystem, gPad, TLegend, TPaveLabel, kBlack


Expand All @@ -39,6 +40,7 @@
JBessel = []
for nu in range(n):
jbessel = TF1("J_0", "ROOT::Math::cyl_bessel_j([0],x)", 0, 10)
ROOT.SetOwnership(jbessel, False)
jbessel.SetParameters(nu, 0.0)
jbessel.SetTitle("")
jbessel.SetLineStyle(1)
Expand Down Expand Up @@ -78,6 +80,7 @@
KBessel = []
for nu in range(n):
kbessel = TF1("J_0", "ROOT::Math::cyl_bessel_k([0],x)", 0, 10)
ROOT.SetOwnership(kbessel, False)
kbessel.SetParameters(nu, 0.0)
kbessel.SetTitle("Bessel K functions")
kbessel.SetLineStyle(1)
Expand Down Expand Up @@ -114,6 +117,7 @@
iBessel = []
for nu in range(5):
ibessel = TF1("J_0", "ROOT::Math::cyl_bessel_i([0],x)", 0, 10)
ROOT.SetOwnership(ibessel, False)
ibessel.SetParameters(nu, 0.0)
ibessel.SetTitle("Bessel I functions")
ibessel.SetLineStyle(1)
Expand Down Expand Up @@ -151,6 +155,7 @@
jBessel = []
for nu in range(5):
jbessel = TF1("J_0", "ROOT::Math::sph_bessel([0],x)", 0, 10)
ROOT.SetOwnership(jbessel, False)
jbessel.SetParameters(nu, 0.0)
jbessel.SetTitle("Bessel j functions")
jbessel.SetLineStyle(1)
Expand Down
68 changes: 0 additions & 68 deletions tutorials/pyroot/fillrandom.py

This file was deleted.

2 changes: 1 addition & 1 deletion tutorials/pyroot/fit1.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#
# We connect the ROOT file generated in a previous tutorial
#
File = "py-fillrandom.root"
File = "fillrandom-py.root"
if (ROOT.gSystem.AccessPathName(File)) :
ROOT.Info("fit1.py", File+" does not exist")
exit()
Expand Down
2 changes: 2 additions & 0 deletions tutorials/pyroot/formula1.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
# We create a formula object and compute the value of this formula
# for two different values of the x variable.
form1 = TFormula( 'form1', 'sqrt(abs(x))' )
ROOT.SetOwnership(form1, False)
form1.Eval( 2 )
form1.Eval( -45 )

# Create a one dimensional function and draw it
fun1 = TF1( 'fun1', 'abs(sin(x)/x)', 0, 10 )
ROOT.SetOwnership(fun1, False)
c1.SetGridx()
c1.SetGridy()
fun1.Draw()
Expand Down
Loading