Objects that are not pointers disappear from TCanvas

Hi,

Why are objects that are drawn on a TCanvas* not persistent if they are not a pointer? Please run the attached script to see the effect. Is there any way to make the the second TLatex object persistent?

ROOT v5.32/01 on Ubuntu 12.04 LTS 64bit.

Thank you,
Jochen
print.C (476 Bytes)

if not a pointer the text does not enter the gPad list of primitives:

Processing print.C...
root [1] gPad->ls()
Canvas Name=c Title=c Option=
 TCanvas fXlowNDC=0 fYlowNDC=0 fWNDC=1 fHNDC=1 Name= c Title= c Option=
  OBJ: TList	TList	Doubly linked list : 0
   TFrame  X1= 0.000000 Y1=0.000000 X2=1.000000 Y2=1.000000
   OBJ: TH1F	hframe	 : 1 at: 0x7fe56245c560
   Text  X=0.250000 Y=0.500000 Text=text stays
root [2] 

Hi,

If an object is declared on the stack (i.e. is not a pointer) by definition of C++, they are destructed when they go out of scope and thus does not survive past the end of the function.

Philippe.