Object Ownership of graphical primitives

I want to draw some graphical primitives in a Canvas and i’m not interested to keep a pointer to these primitives for example to modify them.

Is it the correct approach? Will the primitives be deleted when canvas is deleted?

TCanvas* EventDisplay = 
new TCanvas("EvtDisplay","Event Display",  0,0,400,800);

  //plot of tubes

  TEllipse* ellipse;
  for (Int_t index; index<20; index++) {
    ellipse = new TEllipse(TrackerWireX[index],TrackerWireZ[index],10);
    ellipse->Draw();
    ellipse->SetBit(kCanDelete);
  };

TCanvas* EventDisplay = new TCanvas("EvtDisplay","Event Display",  0,0,400,800);
// plot of tubes
TEllipse ellipse;
for (Int_t index; index<20; index++)
   ellipse.DrawEllipse(TrackerWireX[index],TrackerWireZ[index],10,0,0,360,0);

see: root.cern.ch/root/htmldoc/src/TE … rawEllipse

but your code is correct too.

I use TEllipse as an example. My question was if I can dinamically construct graphical primitives objects and attach them to the canvas, being sure that they will be deleted with the canvas and i do not commit some other memory management error.

When clearing a pad, all primitives for which their bit kCanDelete is set are automatically deleted.
When the DrawCopy function is used, the kcanDelete bit is set for the copy.

Rene