You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The pythonization of TDirectoryFile has a _TDirectoryFile_Get function (used to implement Get()) that may return a TObject whose memory is not owned by either c++ or python, causing a memory leak.
I attempted to fix the issue with a simple ROOT.SetOwnership, but that causes some tests to fail, specifically pyunittests-pyroot-pyz-tdirectoryfile-attrsyntax-get.
Reproducer
in python, open a TFile containing many different objects (e.g. histograms)
Get all those objects using file.Get(name) in a for loop (relinquishing their reference at every iteration)
see the memory increase forever.
You can test the bug with the following script:
import resource
import ROOT
def print_memory_usage(message):
print(f"{message:50} {resource.getrusage(resource.RUSAGE_SELF).ru_maxrss}")
print_memory_usage("start")
histogram_names = open("histogram_names.txt").read().splitlines()
print_memory_usage("read histogram names")
fn = "NTUP_PHYSVAL.40023485._000001.pool.root.1"
with ROOT.TFile.Open(fn) as f:
print_memory_usage("open ROOT file")
for i, histogram_name in enumerate(sorted(histogram_names)):
h = f.Get(histogram_name)
if i % 1000 == 0:
print_memory_usage(f"read {i+1} histograms")
print_memory_usage("read all histograms")
print_memory_usage("outside context maneger (closing ROOT file)")
The files used were provided by the user who reported the issue, see the forum post
Check duplicate issues.
Description
The pythonization of
TDirectoryFile
has a_TDirectoryFile_Get
function (used to implementGet()
) that may return a TObject whose memory is not owned by either c++ or python, causing a memory leak.I attempted to fix the issue with a simple
ROOT.SetOwnership
, but that causes some tests to fail, specificallypyunittests-pyroot-pyz-tdirectoryfile-attrsyntax-get
.Reproducer
file.Get(name)
in afor
loop (relinquishing their reference at every iteration)You can test the bug with the following script:
The files used were provided by the user who reported the issue, see the forum post
ROOT version
master
Installation method
built from source
Operating system
Linux
Additional context
This bug was reported on the forum
The text was updated successfully, but these errors were encountered: