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:
_Platform: Ubuntu 22.04