Re: [ROOT] When to delete Root objects?

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri Oct 18 2002 - 08:33:29 MEST


Hi Aldo,

When you call m_AllGraphs->Draw or m_SillyGraph->Draw
or m_CollHisto->Draw, a reference to these objects is added
to the list of the primitives in the pad/canvas.
When you clear the canvas, the list is cleared but the objects
are not deleted, unless explicitly specified when their bit kCanDelete
is set (see chapter Object Ownership in the Users Guide page 107).
In the case of the objects you mention, they will not be deleted
when you clear the pad.
If you want these objects to be automatically deleted when you clear
teh pad, you can do, eg:
 m_AllGraphs->SetBit(kCandelete);

This bit is automatically set for the low level graphics objects such as
lines, texts, labels, but not for histograms, graphs or trees.

Rene Brun


On Thu, 17 Oct 2002, Aldo F. Saavedra wrote:

> 
> Hi,
> 
> I have the following gap in my understanding of
> the root framework.
> 
> I'm working on a application that uses ROOT classes
> and QT.
> 
> I have a dialog class. When created, a TCanvas object
> together with a few TGraph, TMultiGraph and TH2
> objects are also created. So we have something like:
> 
> TCanvas *m_canvas;
> TMultiGraph *m_AllGraphs;
> TGraph *m_SillyGraph;
> TH2 *m_CoolHisto;
> 
> and in the constructor
> 
> m_canvas = new TCanvas("ExtraCanvas","Floating",topx,topy,width,height);
> m_AllGraphs = new TMultiGraph("All","");
> m_SillyGraph = new TGraph(10);
> m_CoolHisto = new TH2("Histo","Foo",50,minx,maxx,50,miny,maxy);
> 
> When I destroy the dialog object and I have not drawn anything on
> the canvas everything is fine. The delete operator works well.
> The problem arises when I draw some of the Root objects.
> 
> I read somewhere in the root website that when drawing on a canvas
> the root objects get attached to a list. It seems that when I
> destroy the canvas the objects on that list are also destroyed.
> So the question is there a way to know if the root object
> has already being deleted by a call to delete m_canvas.
> 
> I thought m_canvas->Clear() would release the root objects
> from the list but does not seem to be the case.
> What I'm trying to do is to release all the memory that was
> allocated by the dialog.
> 
> Any help would be appreciated.
> 
> 
> 
> Cheers,
> Aldo
> 
> 
> 
> 
> ***********************************************************
>  Aldo F. Saavedra
>  ATLAS Collaboration - Pixel Group (Physics Division)
>  Lawrence Berkeley National Laboratory
> 
>  Email:          AFSaavedra@lbl.gov
>  Phone:          1 510 486 4690
>  Fax:		 1 510 486 5101
>  Postal Address: Lawrence Berkeley National Laboratory
>                  1 Cyclotron Rd Mailstop 50B-6208
>                  Berkeley, CA 94720
>                  USA
> 



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