Hi, I have seen some unexpected behavior in a TTree that I'd like to ask about. The tree in question had two branches which were objects (among other branches of numerical types). Both objects inherit from the same parent class (TPhTrack), which ultimately inherits from TObject. When caling TTree->Branch([name],[class],&[pointer],32000,0) on both, the first branch (a TPhMCTrack) becomes a TBranchElement, while the second (a TPhSpecTrack) becomes a TBranchObject. My first question is why would happen. Neither object (TPhMCTrack or TPhSpecTrack) has a custom streamer and both were called with splitlevel==0. The parent class of both these objects (TPhTrack) has a TObjArray* member, which owns its objects. For the objects in the TBranchObject, TPhSpecTrack, there was no memory leak when reading the tree with Draw() or GetEntry() -- the objects in the TObjArray* would get deleted or overwritten (I guess the latter). However, for the TBranchElement, TPhMCTrack, the objects in the TObjArray* would never get deleted or overwritten, and there was a serious memory leak. The difference in the way these objects are read is the difference between the default streamer in TPhSpecTrack from ClassDef() and the streamer that is created by the TStreamerInfo / TStreamerBase for the TPhMCTrack's TBranchElement. My second question is why does this problem occur? In an attempt to prevent the memory leak, I called TBranch::SetAutoDelete() on both branches. The TBranchObjects would get deleted, but the TBranchElements would not (having put a print statement in the destructors of both, I know this is the case). I looked through the code and could not find any place where the SetAutoDelete() flag is checked for TBranchElements. Also, in the TStreamerInfo::ReadBuffer() type that was being used (kBase), I didn't see any place where it checked the ok-to-delete bit of the object, but perhaps I missed it somewhere in TClass::ReadBuffer(). Anyway, my last question is: Does TBranchElement ignore the SetAutoDelete() flag and if not, why were my objects in this branch not being deleted? As a final note, if a use TTree::BranchOld() and call the SetAutoDelete() flag, I have no memory leaks. Thanks for the help!
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:58 MET