[ROOT] About TTree::Branch

From: david.chamont@poly.in2p3.fr
Date: Thu Jun 06 2002 - 03:28:58 MEST


Hi rooters,

After a round with branches, I want to report
about several behaviors which I find suspect. I work
with g++ 2.95.2 under Linux redhat 6.1, and the
class I try to make persistent is basically something
like this :

   template <class T>
   class MyArray
    {
     ...
     private:
       int size
       T * elements ; // [size]
     ...
    } ;

I have added many display in MyArray and T constructors
and destructors to track where I go. Here are the
behaviors which disturb me :

1) If I call TTree::Branch on a null pointer to MyArray
      I observe that a MyArray is contructed,
      a T is contructed, a T is destructed, and that's all.
      The MyArray destructor has not been called, yet
      the pointer is still null. Isn't it a memory leak ?

2) If i call TTree::SetBranchAddress on a null pointer,
      I observe that a MyArray is constructed
      and the pointer is not any more null. This difference of
      behavior with TTree::Branch is on purpose ? Is it
      necessary for ROOT, or just expected to help the user ?
      In my case, it does not help, since my strategy is to
      attach the branch to the pointer at the moment, and
      affect later the good value to the pointer.

3) If I fill the tree wih an empty array (size and elements
      attributes are null), put it in a file, and later open the
      file and I get the corresponding entry, the size is
      correctly set to 0, but the pointer is left unchanged.
      If I get another entry, the tree
      try to delete the pointer and crash.

4) i tried to solve 3) by setting AutoDelete to kFALSE
     on the branch, but I observed no effect. the T destructors
     are still called. i misunderstood the role of AutoDelete ?
     it is not expected to avoid calls to destructors between
     two calls to GetEntry ?

David C.



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:55 MET