Large memory footprint in TProfile

Dear all,
I’ve got a bit of a mystery here.

I’ve got two sets of 1024 2-D histograms (TH2S), “A” and “B”.
“A” histograms are 165x1024, while “B” histograms are 25x1024.

After filling all my 2-D histograms, I create a TProfile for each histogram.
for i in 0…1023:
profileA[i] = histogramA[i]->ProfileX()
… work … work …
profileB[i] = histogramB[i]->ProfileX()
… work … work …

And I’m saving all these histograms and profiles into a ROOT file.
For “A”, everything works fine: each TH2S takes ~343kB and each TProfiles takes ~22 kB.
For “B”, each TH2S is ~55kB but each TProfile is 2MB! The contents seem to be correct and the program produces the expected results, but it’s using a lot more memory and disk space.

For debugging, I’ve made the software run like this:
for i in 0…1023:
profileA[i] = histogramA[i]->ProfileX()
… work … work …
profileB[i] = histogram[color=#FF0000]A[/color][i]->ProfileX()
… work … work …

Of course, this doesn’t produce correct results but it no longer uses so much memory either.

At this point, I’m considering everything, including a possible memory corruption within my program.
But I’ve made a lot of changes and a) the program still works fine b) the unexpectedly big TProfiles remain.

I’m using ROOT 5.34.

If anyone has a clue or an educated guess about what’s going on, I’d be very thankful.

Of course, it’s always after you ask for help that you find the solution.
For future reference, the culprit was a function fitted to the histogram, whose number of points was being set to 250k. :neutral_face: