# A question about ROOT

**URL:** <https://root-forum.cern.ch/t/a-question-about-root/62617>\
**Category:** ROOT\
**Tags:** python, hist\
**Created:** [January 9, 2025, 1:57pm UTC](https://root-forum.cern.ch/t/a-question-about-root/62617 "2025-01-09T13:57:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiangjun](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/x/a9a28c/32.png) [@xiangjun](https://root-forum.cern.ch/u/xiangjun)\
**Post date:** [January 9, 2025, 1:57pm UTC](https://root-forum.cern.ch/t/a-question-about-root/62617/1 "2025-01-09T13:57:47Z")

</div>

Dear experts,

I got an interesting question about ROOT. This is the part of my python script.

> 12 new\_iso\_tight = hist\_iso\_tight.Clone(“new\_iso\_tight”) #now only 50 bins or 60 bins  
> 13 # exit()  
> 14 new\_iso\_tight.SetTitle(new\_hists\_name\_data[i][j])  
> 15 # exit()

First I’m working on lxplus,then  
Condition1 :  
python3 this script  
I got an error **" corrupted size vs. prev\_size while consolidating"**  
The root version is 6.34.02

Conditon2 :  
setupATLAS  
lsetup “root 6.32.08-x86\_64-el9-gcc13-opt”  
python3 my script  
No probelm, the root version is 6.32.08

By using exit() to debug, I found the related code are these two line codes.  
I just want to know what’s the difference of these two version root for this related probelm.

Many thanks in advance!

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [January 9, 2025, 2:02pm UTC](https://root-forum.cern.ch/t/a-question-about-root/62617/2 "2025-01-09T14:02:17Z")

</div>

Can you provide a reproducer we can run to see the issue?

---

<div class="post-metadata">

**Author:** ![jonas](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jonas/32/24756_2.png) [@jonas](https://root-forum.cern.ch/u/jonas)\
**Post date:** [January 9, 2025, 3:09pm UTC](https://root-forum.cern.ch/t/a-question-about-root/62617/3 "2025-01-09T15:09:00Z")

</div>

With ROOT 6.34, the memory management of of Histograms in PyROOT has changed a bit. Maybe you are accessing an invalid pointer, which could be in this case the `hist_iso_tight` or the ` new_iso_tight`.

@bellenot is right, a full reproducer would be nice, byt I also don’t understand from your report which line of the two causes the crash actually. Is it `hist_iso_tight.Clone()` or `new_iso_tight.SetTitle()`? What happens if you comment out the `SetTitle()`, will it still crash? And how is the `histo_iso_tight` created? If it’s not possible to share a reproducer, at least some more code, context and investigation of the problem from your side would be appreciated.

Thanks!

---

<div class="post-metadata">

**Author:** ![xiangjun](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/x/a9a28c/32.png) [@xiangjun](https://root-forum.cern.ch/u/xiangjun)\
**Post date:** [January 10, 2025, 3:43am UTC](https://root-forum.cern.ch/t/a-question-about-root/62617/4 "2025-01-10T03:43:57Z")

</div>

Hi all,  
No problem!

I have created a public link, all input files and scripts are uploaded.  
[https://cernbox.cern.ch/s/5h7ySnixJCJwuAF](https://cernbox.cern.ch/s/5h7ySnixJCJwuAF)  
you can run by

> source test.sh

the related code is at line 264,

> hist\_iso\_tight.Clone()

My code is not good, thank you for you attention 😀

---

<div class="post-metadata">

**Author:** ![jonas](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jonas/32/24756_2.png) [@jonas](https://root-forum.cern.ch/u/jonas)\
**Post date:** [January 10, 2025, 4:34am UTC](https://root-forum.cern.ch/t/a-question-about-root/62617/5 "2025-01-10T04:34:12Z")

</div>

Great, thanks for sharing!

The problem is because you’re having a bunch of TFiles opened, and any newly created histogram is automatically owned by the currently-opened file. At the end of the Python process (in this case your `exit()`), the ROOT objects are deleted in a random order, and if the histogram is deleted after the file there will be an invalid memory access and a crash.

We’ll avoid this problem in the next ROOT release by telling PyROOT that is should not delete these histograms created by `Clone()` itself.

For now, the workaround is to manually unset the owning directory of these histograms:

```python
new_iso_tight.SetDirectory(ROOT.nullptr)

```

---

<div class="post-metadata">

**Author:** ![xiangjun](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/x/a9a28c/32.png) [@xiangjun](https://root-forum.cern.ch/u/xiangjun)\
**Post date:** [January 10, 2025, 8:48am UTC](https://root-forum.cern.ch/t/a-question-about-root/62617/6 "2025-01-10T08:48:24Z")

</div>

OK! Thank you very much!

---

<div class="post-metadata">

**Author:** ![jonas](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jonas/32/24756_2.png) [@jonas](https://root-forum.cern.ch/u/jonas)\
**Post date:** [January 23, 2025, 6:03am UTC](https://root-forum.cern.ch/t/a-question-about-root/62617/7 "2025-01-23T06:03:29Z")

</div>

For the record: the fix has been merged and it was also backported to the 6.34 release branch. Therefore it will be part of the next patch release, ROOT 6.34.04:

> <https://github.com/root-project/root/pull/17399>
>
> Following up on #17250, also pythonizing the \`TObject::Clone()\` overrides to aut…omatically give up the ownership.
> 
> Thanks to the following forum post for noticing this problem: https://root-forum.cern.ch/t/a-question-about-root/62617

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [February 6, 2025, 6:04am UTC](https://root-forum.cern.ch/t/a-question-about-root/62617/8 "2025-02-06T06:04:25Z")

</div>

Closed on February 6, 2025, 6:04am UTC

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