Drawing histogram by calling TTree Draw causes memory leak

Hello, I am trying to use the line to make TH1F histograms:


There are no problem of making the task done. However, it seems to occupy some memory that cannot be deleted, even I have tried different methods to free the histograms. It becomes a problem when I repeat this more than (about) 700 times on my end.

I do a test by only making a few histograms. The memory keeps building up even the function with this line is finished or the root file is closed.

The only way to drop the memory is to end the program entirely, so I think this is a bug that needs to be fixed. Or is there anything I can do about it?


Maybe @pcanal can take a look and fill a bug report if needed, if you tell us which version of ROOT, which OS, and which compiler…

The ROOT version is 6.12/04; it is built for linuxx8664gcc.

and welcome to the ROOT forum. Each TTree::Draw invocation just-in-time-compiles C++ code that implements your histogram filling/variable selection. That compiled code will reside in memory until program exits.

An alternative that does not use just-in-time compilation (because the template parameters of Histo1D are explicitly specified):

auto h = ROOT::RDataFrame("treename", "filename.root").Histo1D<double, double>("variable", "weight");


This code should not lead to an increase in memory after you delete the histogram. Can you provide a complete running example that shows the memory increase?

1 Like

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