Re: [ROOT] another two stupid questions.

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Feb 19 2002 - 13:40:40 MET


Hi Jacek,

In your example, you add the graph to the current directory.
When drawing a TGraph, an intermediate TH1 object is created.
This object has the same as the graph. When the histogram is created, it is
added to the current directory and replaces any
previous object with the same name. You can see this from the Warning message.
The solution for you is:
  - to not add the graph to gDirectory, but to any other               
collection.
  - or call TH1::AddDirectory(kFALSE) befor drawing the graph

Rene Brun

Jacek M. Holeczek wrote:
> 
> Hi,
> > (... Question One ...)
> > I do not understand this problem. You do not need to reset the bit
> Assume the following in the subroutine :
>         TGraph *g = new TGraph(n, xtable, ytable)
>         g->SetName("ACPE23Mat250NS"); g->SetTitle("ACPE23Mat250NS");
>         gDirectory->Append(g);
> Then, outside of the subroutine :
>         root [2] gROOT->FindObject("ACPE23Mat250NS")
>         (const class TObject*)0x8ec4c90 // IT IS THERE
>         root [3] ACPE23Mat250NS->Draw("ALP")
>         <TCanvas::MakeDefCanvas>: created default TCanvas with name c1
>         Warning in <TH1::Build>: Replacing existing histogram: ACPE23Mat250NS (Potential memory leak).
>         root [4] gROOT->FindObject("ACPE23Mat250NS")
>         (const class TObject*)0x8ec4c90 // IT IS STILL THERE
>         root [5] c1->Clear()
>         root [6] gROOT->FindObject("ACPE23Mat250NS")
>         (const class TObject*)0x0 // IT IS GONE
> And ... my graph is lost forever.
> I tried to protect myself against it using (in my subroutine) :
>         g->ResetBit(kCanDelete); g->ResetBit(kMustCleanup);
> before gDirectory->Append(g), but it didn't help.
> Thanks in advance,
> Jacek.



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:42 MET