Memory out of control

I would like to do a simple analysis on a data set that is already in .root form. However I find that when looping over many events the memory use increases like a memory leak.

I have run the MakeClass() method to generate myself a class. My Loop() method looks something like this:

struct structure{
variable;
}vars;

Loop(){
TTree* oak=new TTree(“oak”,“my tree”);
oak->Branch(“Variable”,&vars.variable,“variable”);

if (fChain == 0) return;
Int_t nentries = Int_t(fChain->GetEntriesFast());
Int_t nbytes = 0, nb = 0;
for (Int_t jentry=0; jentry<nentries;jentry++) {
Int_t ientry = LoadTree(jentry);
if (ientry <0>GetEntry(jentry); nbytes += nb;
// if (Cut(ientry) < 0) continue;

  if(something<5>Fill();
   }

}
TFile *output=new TFile(“out.root”,“recreate”);
oak->Write();
output->Close();
}

I know that the every increasing memory use is caused by filling the tree (when I comment out the fill() line the memory leak disapears).

How can I get arround this because I eventually want to run my program over millions of events?

John

Move the creation of the file before the creation of the Tree.

Rene