I have a problem with a ttree that grows without stop when running a program of mine. I open the TFile before the TTree, so it should be a disk resident tree. Also, my code
does not eat memory if I remove the “ttree->Fill()” line. Trying to find out was is going wrong I wrote a short program filling a tree. I ran this for different number of entries filled
into the using valgrind and the massif tool. It seems to me that this simple program
conumes more memory as times (the number of entries) goes by. This is not the way it should be, is it? I include the program and two plots from massif.
I use 5.14/00b
and
Linux 2.6.9-42.0.3.ELsmp #1 SMP Thu Oct 5 16:29:37 CDT 2006 x86_64 x86_64
x86_64 GNU/Linux
In your example you are writing 17 Gigabytes of uncompressed data (500 Mbytes after compression). You have a bug in your test (testtree->Fill) in the loop!). Also because your data is full of zeros, the only thing that you write are the dynamic tables for the baskets. If your application is really close to your example you should increase the branch basket size to reduce the number of baskets. I have made the corresponding changes in your modified example below (with which you will not see a memory increase).
Rene
void ttreetest()
{
TFile testfile("testfile.root","RECREATE");
TTree *testtree = new TTree("Atreetest","test a tree");
Double_t Es[256],Ts[256],P2s[256];
Int_t N = 0;
int basketsize = 512000; //change basket size from default 32k to 512k
testtree->Branch("N",&N,"N/I",basketsize);
testtree->Branch("E",Es,"E[N]/D",basketsize);
testtree->Branch("T",Ts,"T[N]/D",basketsize);
testtree->Branch("P2",P2s,"P2[N]/D",basketsize);
while(testtree->GetEntries()<10000000){
N = (N+1)%100;
for (int i=0; i<N; i++){
Es[i] = Ts[i] = P2s[i] = i;
}
testtree->Fill(); //<=== moved out of the loop !
}
testtree->Write();
testfile.Close();
}
I did mess up a bit in the example, the tree->Fill() should have been outside the for loop…
Anyway, it was (as expected?) not a problem with the TTree that caused my problems. They were caused by another part of my application, but only showed up if I filled the tree. C++ is sometimes a bit tricky…