# TTree memory corruption

**URL:** <https://root-forum.cern.ch/t/ttree-memory-corruption/64420>\
**Category:** Newbie\
**Created:** [November 19, 2025, 10:15am UTC](https://root-forum.cern.ch/t/ttree-memory-corruption/64420 "2025-11-19T10:15:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![phylmath](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/phylmath/32/38400_2.png) [@phylmath](https://root-forum.cern.ch/u/phylmath)\
**Post date:** [November 19, 2025, 10:15am UTC](https://root-forum.cern.ch/t/ttree-memory-corruption/64420/1 "2025-11-19T10:15:52Z")

</div>

* * *

_ROOT Version:_ 6.32.04  
_Platform:_ WSL2 Ubuntu

Hello! I am getting an error when storing large ROOT files. For context, I am generating 5 million events in PYTHIA, storing results into multiple TTrees, and then reading these in another script to study. When running the second script, I get repeated errors in my terminal as shown below.

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/c/3/c35f3d3e990d6560e3157b227aede6536e10ed4f.png)

To make it readable, I have copy-pasted the repeating error message below:

`R__unzip: error -5 in inflate (zlib)`  
`Error in `\<`TBasket::ReadBasketBuffers`\>`: fNbytes = 4836146, fKeylen = 77, fObjlen = 5301454, noutot = 0, nout=0, nin=4836069, nbuf=5301454`  
`Error in `\<`TBranchElement::GetBasket`\>`: File: 4-GenData/gen_FCC365.root at byte:6790900984, branch:parEto, entry:3701793, badread=1, nerrors=9, basketnumber=397`  
`R__unzip: error -5 in inflate (zlib)`  
`Error in `\<`TBasket::ReadBasketBuffers`\>`: fNbytes = 4836146, fKeylen = 77, fObjlen = 5301454, noutot = 0, nout=0, nin=4836069, nbuf=5301454`  
`file probably overwritten: stopping reporting error messages`  
`===>File is more than 2 Gigabytes`  
`R__unzip: error -5 in inflate (zlib)`  
`Error in `\<`TBasket::ReadBasketBuffers`\>`: fNbytes = 4836146, fKeylen = 77, fObjlen = 5301454, noutot = 0, nout=0, nin=4836069, nbuf=5301454`

I am guessing this has something to do with exceeding the memory of the TTree itself? Since I do not face this issue with 1M samples (the file size is now 8.9GB). Looking forward to your inputs. 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:** [November 19, 2025, 12:22pm UTC](https://root-forum.cern.ch/t/ttree-memory-corruption/64420/2 "2025-11-19T12:22:47Z")

</div>

Did you try to search the forum? [Search results for 'R\_\_unzip: error -5 in inflate order:latest' - ROOT Forum](https://root-forum.cern.ch/search?q=R__unzip%3A%20error%20-5%20in%20inflate%20order%3Alatest)  
If you did and didn’t find any suitable answer, then maybe we can ask @pcanal to take a look

---

<div class="post-metadata">

**Author:** ![phylmath](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/phylmath/32/38400_2.png) [@phylmath](https://root-forum.cern.ch/u/phylmath)\
**Post date:** [November 19, 2025, 1:29pm UTC](https://root-forum.cern.ch/t/ttree-memory-corruption/64420/3 "2025-11-19T13:29:35Z")

</div>

Hello. Yes, I had searched the forum but the two closest cases don’t have a resolution.

> [@TBasket Problem in root](https://root-forum.cern.ch/t/tbasket-problem-in-root/28313/4):
>
> While the code is running, It is giving this error. It still could be a corrupted file. To exclude this possibility, just write a small example that ‘just’ loop over the entries and call GetEntry, if that works then the file is fine. What is going wrong in this process. I was suspecting, there is some memory issue. You could run your failing example under valgrind with the option --suppressions=$ROOTSYS/etc/valgrind-root.supp and it might give you more information if the problem is ‘memo…

> [@TBasket errors when looping over TTree](https://root-forum.cern.ch/t/tbasket-errors-when-looping-over-ttree/24395):
>
> Hi, I have a tree with 3.7M events, with most branches being vectors of floats or ints. I get thousands of this kind of error at various times with various scripts about 2.2M into the event: Error in \<TBasket::ReadBasketBuffers\>: fNbytes = 189808, fKeylen = 82, fObjlen = 209182, noutot = 0, nout=0, nin=189726, nbuf=209182 Error in \<TBranchElement::GetBasket\>: File: /afs/cern.ch/work/c/cschnaib/public/P5Neutron/ana\_p5.root at byte:16857682192, branch:rh\_pos\_x, entry:2438758, badread=1, nerrors…

Hence hoping I can get input here. In any case, I have kept the simulations to run again with the following additions to increase TTree size and widen basket size. I will check if it works now.

```cpp
tree->SetMaxTreeSize(200LL * 1024 * 1024 * 1024);
const int BASKET = 128000;
tree->GetBranch("branch_1")->SetBasketSize(BASKET);
.
.
tree->GetBranch("branch_23")->SetBasketSize(BASKET);

```
