Can a TPad be made non-owner of its primitives?

Hi,

I’m using the default TObject::Draw() method to add some of my objects to a TCanvas (embedded in a TRootEmbeddedCanvas), and I kind of forgot that then the TCanvas is the owner of those objects, which, in this very case, I would not like.
Is there a way to instruct the TCanvas not to cleanup ?

Thanks,

Using root 5.16/00 on macosx (intel)

Only objects in the pad list of primitives that have their kCanDelete bit set are deleted when clearing the pad. If you do not set this bit yourself, your object will not be deleted when clearing the pad.

Rene

Hi Rene,

Thanks for your answer. BTW, I discovered the root of my problem (no pun intendend :wink: ). The object I’m drawing is a clone. MyClass copy for implemented in term of Copy(TObject&) const, like other TObjects. But for some reason, I had overwritten the TObject’ Clone method by :

TObject* Clone(const char* newname) const { return new MyClass(*this); }

Turns out that the TObject::Copy method sets the kCanDelete bit to 1 (and hence my overriden Clone got me this bit to 1 as well), while the default TObject::Clone() does not. Don’t understand everything, but by removing my “custom” clone, my cloned object had the kCanDelete to zero and all was fine.

Regards,

Hi,

I’ve found why I made my class’ Clone looks like :

TObject* Clone(const char* newname) const { return new MyClass(*this); }

in the first place.

It’s because MyClass has a pointer to some other object which is shared amongst several MyClass objects. If I use TObject::Clone() default method (using the Streamer), this pointer is duplicated as well, which I prefer not (as it’s a big object).

So now I’m back to my initial problem of having to deal with kCanDelete set to 1. Do I simply have to force it back to zero in MyClass::Copy or is there something I’m missing ?

Thanks,

Yes you must reset this bit in your Copy function.

Rene