Re: TH1::Build(), memory leakage

From: Margar Simonyan <simonyan_at_mail.cern.ch>
Date: Mon, 4 Jul 2005 14:00:44 +0200 (CEST)

in "Object Ownership" chapter it is written that histograms are owned by gDirectory (default) . I create TH1 object with new, it is added to gDirectory list, if I call delete operator, then we have double delete problem, since gDirectory will try to delete object, is it right ? Another related question. In THStack documentation it is written, "The THStack owns the objects in the list". What it means ? I create TH1 object with new, add to stack with THStack::Add(). Should I delete TH1 object with delete operator. I suppose no, since it is owned by THStack.

Margar Simonyan

On Mon, 4 Jul 2005, Rene Brun wrote:

> When you create an object (eg TH1) with new, it is up to you to manage
> this object.
> See chapter about "Object Ownership" in the Users Guide
>
> Rene Brun
>
> On Sun, 3 Jul 2005, Margar Simonyan wrote:
>
> > Dear users of ROOT
> >
> > I would like to know why in TH1::Build() delete hold is
> > commented. If one have a function which crates histogram with new then
> > there is no (easy) way to avoid memory leakage.
> >
> > Best regards,
> > Margar Simonyan
> >
> > if (hold) {
> > Warning("Build","Replacing existing histogram: %s (Potential
> > memory leak).",GetName());
> > gDirectory->GetList()->Remove(hold);
> > hold->SetDirectory(0);
> > // delete hold;
> > }
> >
>
Received on Mon Jul 04 2005 - 14:03:09 MEST

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:10 MET