Hi John, A statement like object->Draw(); adds a reference to object in the list of primitives of the current pad. When you clear a pad, two things happen: 1- the references to the objects in the pad are moved. 2- an object is deleted if its "kCanDelete" bit is set. 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
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:34 MET