Rene,
this cannot be true. Root reads the two TNamed objects from a file. This
means, that root allocates memory for it. In other words, what you say
is: If one doesn't want to overload the Streamer function (make sure
that the Bit/Flag is Set) there is no way, that the TNamed object will
ever be deleted in the case of 'Obj1'.
If I now store more of these object in a tree, referencing the same
TNamed, root stores the TNamed only once (Am I correct?). Assume, that
in a program I created this TNamed is created by the user calling
SetName(new TNamed) and the pointer is distributed to the other class A
objects. If I now read such class A objects from a Tree I would, at the
end, delete the TNamed object several times...
How does I (or root) know whether an object referenced by my object has
been created by the user, the class itself or the root environment? And
how do I make sure, that in any circumstances the objects are deleted
exactly once?
Thomas.
Rene Brun wrote:
> Thomas,
>
> In one case you call SetBit, in the other one you call ResetBit!!
>
> Rene Brun
>
> Thomas Bretz wrote:
>
>>Dear rooters,
>>
>>here is a simplified example to illustrate my question: If I have a class
>>
>>class A : public TObject {
>> TNamed *fNamed;
>> ~A() { if (TestBit(BIT(14)) delete fNamed; }
>> void SetName(const char *name)
>> { fNamed = new TNamed(name, ""); SetBit(BIT(14)); }
>> vodi SetName(TNamed *name) { fNamed = name; ResetBit(BIT(14)); }
>> ClassDef(A, 1)
>>}
>>
>>and now I create an instance of this class
>>A a, b;
>>a.SetName(new TNamed);
>>b.SetName("NewName");
>>
>>and write both objects to a file:
>>a.Write("Obj1");
>>b.Write("Obj2");
>>
>>now I read this object into new objects:
>>A c,d;
>>c.Read("Obj1");
>>d.Read("Obj2");
>>
>>As I understand it, now both objects (c and d) have a newly allocated
>>TNamed. But for one of the two objects BIT(14) is set and for one not.
>>How can I make sure, that the destruction of the TNamed-data-member is
>>done correctly in any case?
>>
>>Thanks in advance,
>>Thomas.
>
>
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:11 MET