Large memory consumption after GetXaxis()->SetBinLabel(...) is called for histograms

Dear ROOT Experts,

I am trying to optimize my analysis code written in ROOT, and after some profiling, I spotted there is a large memory consumption (~ 50 Mb) immediately after hist->GetXaxis()->SetBinLabel(…) is called.

You can reproduce this by compiling first the following trivial code snippet as a reference:

TProfile *tmp = new TProfile(“tmp”, “tmp”, 1, 0., 1.);

The memory profile is in snapshot_1.

Then, please compile this one:

TProfile *tmp = new TProfile(“tmp”, “tmp”, 1, 0., 1.);
tmp->GetXaxis()->SetBinLabel(1, “a”);

The memory profile for this case is in snapshot_2.

As you can see, there is a dramatic increase of 50 Mb, merely after one bin label is set.

Thanks!

Cheers,
Ante

$ root --version
ROOT Version: 6.32.06
Built for linuxx8664gcc on Apr 03 2025, 03:21:56
From tags/v6-32-06-alice1@v6-32-06-alice1

$ g++ --version
g++ (GCC) 14.2.0

Hi,

Thanks for sharing these details.
could you please share the executable you are compiling?

Best,
Danilo

Dear Danilo,

Thanks for your feedback!

I have stripped down the executable to the bare bones, here is the minimal code snippet in the file BareBones.C which nails down the problem:

#include <TProfile.h> 

int BareBones()
{
 TProfile *tmp = new TProfile("tmp", "tmp", 1, 0., 1.);
 tmp->GetXaxis()->SetBinLabel(1, "a");
 return 0;
}

int main()
{
 BareBones();
 return 0;
}

After initializing ROOT environment, I compile with:

g++ -o BareBones-exe BareBones.C `root-config --cflags --libs`

Then, I run valgrind with:

valgrind --tool=massif --time-unit=ms ./BareBones-exe

Finally, I visualize memory consumption with:

massif-visualizer massif.out.3759370

You need to replace 3759370 above with the PID you got after running valgrind.

Thanks!

Cheers,
Ante