How to delete RDataFrame and clean up memory

Hi Daniil,
the del at the end of loopDataFrame is redundant, df is deleted at the end of the function call. @etejedor can correct me if I’m wrong, but I think PyROOT guarantees that when the last python variable referencing a given python object goes out of scope, the underlying C++ object is deleted.

So even without the del, the C++ RDataFrame object should go out of scope and its memory should be freed.

In your case, the question is rather “what is allocating memory and never freeing it?”. It’s possible that the culprit is the ROOT interpreter: RDataFrame just-in-time compiles (jits) C++ code (for example, "lep_0_p4.Pt()" is jitted into a corresponding C++ function, and Histo1D(model, "myP4") is jitted in the template call Histo1D<float>(model, "myP4").
The memory allocated by the ROOT interpreter contains code, and is never released.

I’m not sure what else might contribute to that memory usage. One could check whether the corresponding C++ program (with and without jitted calls) uses less memory and how much. Or a tool like valgrind --tool=massif might help in identifying memory hoggers.

I’m available for further clarifications!
Cheers,
Enrico

1 Like