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

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Nov 29 2001 - 08:34:19 MET


Hi Stephane,

You did not provide enough information in your original mail.
The answer from Tim is correct. However, I suspect that the leak
comes from the fact that you never release the objects created in your function
draw. If you call your function draw multiple times, you keep opening files,
reading objects from these files in memory and you never delete them.
This should be obvious from the result of gObjectTable->Print().

Rene Brun


Stephane Tourneur wrote:
> 
> Thanks a lot for your response.
> But changing the two lines (TH1D* hd = new TH1D(); hd =
> plot->ProjectionX("",50,50);) into one line (TH1D* hd
> = plot->ProjectionX("",50,50);) doesn't change anything to the heap
> size...
> I still get the same numbers as output of gObjectTable->Print() and my
> application still freezes due to the memory leak.
> Any other suggestions?
> 
> Stephane
> 
> On Wed, 28 Nov 2001, Timothy E. Miller wrote:
> 
> > On Tue, 2001-11-27 at 20:49, Stephane Tourneur wrote:
> > > 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);
> >
> > At this point, you have replaced the TH1D object you created
> > with another one generated by the ProjectionX() function call.
> > When you delete hd later in the code, you delete the ProjectionX()
> > object and not the one created by the 'new TH1D()' call.
> >
> > Thus, the previous line 'TH1D* hd = new TH1D()' is not necessary.
> >
> > Also, replace
> >      hd = plot->ProjectionX("",50,50);
> > with
> >      TH1D* hd = plot->ProjectionX("",50,50);
> >
> > As for the difference in size of the leak, I do not know.
> > Cheers,
> > -Tim
> >
> >
> >



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