Hi Paolo, This is not a limitation, it is a question of principle. When reading a class object (say MyClass) from a file, Root calls the default constructor MyClass *a = new MyClass(); then reads the object from the TBuffer b via a->Streamer(b) If MyClass contains a pointer to, eg AnotherClass *p; MyClass::Streamer will call the default constructor of AnotherClass to read the object, etc. There are two special cases. -if in MyClass, the declaration for AnotherClass is AnotherClass *p //! this member is transient only you can allocate p in the default constructor of MyClass -if in MyClass, the declaration for AnotherClass is AnotherClass *p; //-> you SHOULD create p in your MyClass default constructor. The symbol "->" in the comment field instructs ROOT that p is always created. In this case p->Streamer(b) is called directly. Note that in the normal case, Root will automatically delete p if p is not null. However this can generate a memory leak is p is a collection of objects. Rene Brun Paolo ADRAGNA wrote: > > Hello everyone, > > I would like to know if it is still valid the foollowing limitation in > ROOT (as explained at page 290 of ROOT Guide): there is no possibility to > allocate space for embedded pointer objects in the default constructors, > because this space will be lost (memory leak) while reading the object. > > Is all this still true or in the meantime something changed? > > Thank a lot, > > Paolo Adragna >
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:13 MET