Hello,
I’ve noticed, that when getting entries from a TTree in PyROOT and reading the contents of the branches, the memory use of the process increases after each GetEntry() and is proportional to the number of branches read. This can easily result in not-handlable consumption. It seem that enforcing garbage collection does not do anything, apart from slowing the script down.
In my case the script starts with ~460 MB memory use, ends with ~760, so 300 MB increase during the process of reading. The tree is 42 MB in size. While I know that python variables may occupy much more memory than the pure data, some memory is clearly not released.
The link to the tree that I’ve used for testing:
And here is the script:
#!/usr/bin/python
import glob
import psutil
import os
import gc
import ROOT
pid = os.getpid()
process = psutil.Process(pid)
data_file = "noice_traces_merged_gp13_2024_01_night_datafiles_185-190.root"
print(f"Memory before get noise: {process.memory_info().rss / 1024 ** 2:.2f} MB")
f = ROOT.TFile(data_file, "read")
t = f.Get("tadc")
bnames = [b.GetName() for b in t.GetListOfBranches()]
for j,e in enumerate(t):
print(j)#, e.event_number, e.run_number, e.trace_ch)
dbr = [getattr(t, bname) for bname in bnames]
print(f"Memory after get entry: {process.memory_info().rss / 1024 ** 2:.2f} MB")
# del dbr
# gc.collect()
ROOT Version: 6.30.06
Platform: Fedora 40