Root Ttree memory

Hello experts,
I tried to store my xB and Q2 values(12 bins) in a Tree. But unfortunately I got a memory issue. I using root 6.20
Could you please help me to figure out this?
I saw many examples about this in the forum.but I cannot understand them.

Here is the snippet.

Void dil(){
TFile *AnaFile = new TFile("xBQ2binning.root", "RECREATE", "Test");
TTree *xBQ2binning_tree = new TTree("xBQ2binning_tree","xBQ2binning_tree”);

Double_t xBj,QSq;
if(xBbinning>-1 && xBbinning<nx && Q2binning>-1 && Q2binning<nQ2){

if(Q2binning==0 && xBbinning==0)xBQ2binning_tree->Branch("xBj_00", &xBj,"xBj/D"); xBQ2binning_tree->Branch("Q2_00", &QSq,"QSq/D");
if(Q2binning==0 && xBbinning==1)xBQ2binning_tree->Branch("xBj_01", &xBj,"xBj/D"); xBQ2binning_tree->Branch("Q2_01", &QSq,"QSq/D");
 if(Q2binning==0 && xBbinning==2)xBQ2binning_tree->Branch("xBj_00", &xBj,"xBj/D"); xBQ2binning_tree->Branch("Q2_00", &QSq,"QSq/D");
 if(Q2binning==1 && xBbinning==0)xBQ2binning_tree->Branch("xBj_10", &xBj,"xBj/D"); xBQ2binning_tree->Branch("Q2_10", &QSq,"QSq/D");
 if(Q2binning==1 && xBbinning==1)xBQ2binning_tree->Branch("xBj_11", &xBj,"xBj/D"); xBQ2binning_tree->Branch("Q2_11", &QSq,"QSq/D");
 if(Q2binning==1 && xBbinning==2)xBQ2binning_tree->Branch("xBj_12", &xBj,"xBj/D"); xBQ2binning_tree->Branch("Q2_12", &QSq,"QSq/D");
if(Q2binning==2 && xBbinning==0)xBQ2binning_tree->Branch("xBj_20", &xBj,"xBj/D"); xBQ2binning_tree->Branch("Q2_20", &QSq,"QSq/D");
if(Q2binning==2 && xBbinning==1)xBQ2binning_tree->Branch("xBj_21", &xBj,"xBj/D"); xBQ2binning_tree->Branch("Q2_21", &QSq,"QSq/D");
if(Q2binning==2 && xBbinning==2)xBQ2binning_tree->Branch("xBj_22", &xBj,"xBj/D"); xBQ2binning_tree->Branch("Q2_22", &QSq,"QSq/D");
if(Q2binning==3 && xBbinning==0)xBQ2binning_tree->Branch("xBj_30", &xBj,"xBj/D"); xBQ2binning_tree->Branch("Q2_30", &QSq,"QSq/D");
if(Q2binning==3 && xBbinning==1)xBQ2binning_tree->Branch("xBj_31", &xBj,"xBj/D"); xBQ2binning_tree->Branch("Q2_31", &QSq,"QSq/D");
if(Q2binning==3 && xBbinning==2)xBQ2binning_tree->Branch("xBj_32", &xBj,"xBj/D"); xBQ2binning_tree->Branch("Q2_32", &QSq,"QSq/D");



Here is my error.
Error in TBufferFile::WriteByteCount: bytecount too large (more than 1073741822)
Error in TBufferFile::WriteByteCount: bytecount too large (more than 1073741822)
terminate called after throwing an instance of ‘std::bad_alloc’
what(): std::bad_alloc


This is very strange and most likely I am missing something.

This code seems to create a TTree with exactly 2 branches (which one exactly depends on the config) and store exactly one entry (a single call to Fill) (and at least in this snippet the data store is not initialized. The only memory leak is that the TFile is not deleted (missing delete AnaFile;).

As is the code can not run out of memory everything is very small.

So there might be a loop somewhere in your code some type of loop and indirectly it is causing the crash (however, as-is the code might not be actually doing what you want).