[ROOT] memory leak and differences between root 2.26 and 3.01

From: Stephane Tourneur (tourneur@fnal.gov)
Date: Wed Nov 28 2001 - 02:49:28 MET


Dear "rooters",

I've got a problem of memory leak that i don't manage to fix, especially
for last CDF root version, that is 3.01.
I isolated the problem and here is a simple code:

file draw.C:

/////////////////////////////////////////////////
#include <TFile.h>
#include <TString.h>
#include <TH1.h>
#include <TH2.h>

void draw ()
{
  TFile *file = new TFile("Histo2D.root");
  TString auxhistname = "Trk vs El (d0) ALL CUTS";
  
  TH2F* plot = (TH2F*)file->Get(auxhistname);  
  TH1F* hphi = new TH1F("","",4,0,4);
  TH1D* hd = new TH1D();   

    hd = plot->ProjectionX("",50,50);          

    hphi->SetBinContent(1,hd->GetMean());
 
    delete hd;
      
  hphi->DrawCopy();
  
  delete hphi;
  delete plot;
  delete file; 
 
}
////////////////////////////////////////////////////


Now, on the root prompt, if i do the following:

root [0] .L draw.C+ 
root [1] gObjectTable->Print();
root [2] draw();
root [3] gObjectTable->Print();

I then get my histogram drawn and the print of ObjectTable shows the heap
size jumping from 47ko to 70ko for root 2.26 and from 48ko to 189ko for
root 3.01... I made an application browsing the CDF silicon histograms
that is looping over a similar loop hundreds of time, and the consequence
of this memory leak is that this application is crashing for root 3.01
although it was fine for older root versions...

How can I avoid this memory leak? Why is root 3.01 leaking 6 times more
than 2.26?


I joined an archive containing the three necessary files to test the
example above.

Thanks a lot  for your always precious help.

Stephane Tourneur, CDF, UC Davis 







This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:10 MET