When Root graphics primitives (TLines, TText, TPads, etc) are created,
this bit is set with a statement like
SetBit(kCanDelete);
Our assumption is that for most graphics primitives, you want the pad to
be
the owner.
You can become the owner for these primitives if you add a statement
like
object->ResetBit(kCanDelete);
If you recode your example like:
TCanvas xxx("xxx", "Canvas x");
TPad* yyy=new TPad("yyy", "Pad y", 0, 0, 1, 1);
yyy->ResetBit(kCanDelete);
xxx.cd();
yyy->Draw();
xxx.Clear()
delete yyy; // this will be OK
Rene Brun
John Zweizig wrote:
>
> Can someone explain the following:
>
> TCanvas xxx("xxx", "Canvas x");
> TPad* yyy=new TPad("yyy", "Pad y", 0, 0, 1, 1);
> xxx.cd();
> yyy->Draw();
> xxx.Clear()
> delete yyy;
>
> results in a segmentation violation. My understanding of TPad is that the
> Clear() method should perform the inverse function of draw i.e. in this
> case, it should remove TPad *yyy from the list of primitives kept by xxx.
> Thus, it should be safe to delete or redraw *yyy once it has been Cleared
> from its parent. This doesn't seem to be the case. Are the primitives
> deleted when they're Cleared? This brings up a related question of who
> owns the graphical primitives once they have been Drawn. I haven't seen
> any discussion of this anywhere in the (www) root documentation.
> Ciao,
>
> John