Memory leak when reading vector<object> from TTree in pyROOT

Dear ROOT,

After upgrading to ROOT v6.26/10, we have run into a memory leak while looping over a TTree and reading data from it with pyROOT. Specifically, we have an event class containing a vector of step objects, which we fetch by calling GetVector() on each of the events in the TTree. GetVector() returns a const reference to a std::vector<StepClass>, which pyROOT is choosing to make a copy of; however, this copy is not being deleted between iterations of the loop. Here is a code snippet of what is happening.

TChain ch("simTree")
for i_entry, entry in enumerate(ch):
    v = entry.fAnalysisEvent.GetVector()
    for step in v:
        ....

When we run this code over multiple GBs of data, we end up using multiple GBs of memory, causing it to crash, which suggests that every single event is being loaded into memory and not cleaned up by the garbage collector.

We have been able to avoid this error by not making this copy and instead directly reading elements from the vector using another access function GetHit(iHit). However, while we have solved our immediate problem, we want to bring your attention to the leak that we ran into. In addition, this is old code that previously worked with ROOT version 6.12/06 (we have not tested it between these two versions). We also found a similar ROOT forum post from years ago that identified a very similar problem, which was since fixed:

Thank you,
Ian Guinn


_ROOT Version:6.26/10
_Platform: Ubuntu 22.04
_Compiler: g++


Here is the topic/post number: 26186/15. The issue in this old post was fixed in JIRA issue ROOT-9025. Our problem isn’t completely identical, since we are getting our array from GetArray() defined in our class rather than from TTree.__get_attr__() as was fixed in that issue, but it seems related.

Hi @iguinn,

Sorry for the late reply from the community. Could you please provide a full minimal reproducer that we could use to debug the issue?

Cheers,
J.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.