Hi rooters,
I have some memory leak problems with my program that I can’t explain.
The code is very trivial, I have to loop on a list of root files containing TTrees and fill some histograms. The problem is that when I execute it on 3-4 files, I get a “killed” message after some minutes. If I run the program with just 1-2 input files it works.
The size of each input file is around 3-4 GB.
I report here the core of the program:
> int main(int argc, char * argv[]) {
>
> // variables declaration
> Double_t energy;
> etc.
>
> // histogram declaration
> TH1D *h1 = new TH1D("","",NBIN, xbins);
> TH1D *h2 = new TH1D("","",NBIN, xbins);
> TH1D *h3 = new TH1D("","",NBIN, xbins);
> etc.
> // arvg[1] is a txt file with the list of input root files
> std::ifstream fin(argv[1], std::ifstream::in);
> std::string fname;
>
> while(1) {
> fin >> fname;
> if(fin.eof())
> break;
> TFile *rootfin = new TFile(fname.c_str(), "read");
> TTree *lev2 = (TTree*)rootfin->Get("TTreelev2");
>
> //set branch addresses
> lev2->SetBranchAddress("energy", &energy);
> etc ...
>
> int nent = lev2->GetEntries();
> for(int iev=0; iev<nent ; ++iev)
> {
> lev2->GetEntry(iev);
> h1->Fill(energy);
> etc.
> }
> delete lev2; // unnecessary because the rootfin->Close()
> rootfin->Close();
> }
> TFile fout(argv[2],"recreate");
> h1->Write();
> etc.
> fout.Close();
Am I missing something about object ownership or am I making some c++ mistake?
I can’t explain why this need so much memory.