TList::Clear() has a special case for objects that have the kCanDelete
bit set in their status word. This bit should be set for objects that have
no other reference outside the list in which they are stored. A Clear()
in such a case would leak the object. This is only for TList's since that
is the data structure we use to keep track of, for example, graphics
primitives in pads that should be deleted when the list is cleared.
I'll check if we need the kCanDelete bit for TDirectories. Otherwise you
can do fr->ResetBit(kCanDelete). (however, in 2.00/10 kCanDelete is not
exported to the interpreter so it works only compiled. In the next version
kCanDelete is exported to the interpreter).
Cheers, Fons.
mayer@ik1.fzk.de wrote:
>
> Dear Rooters,
>
> there seems to be a problem with TList::Clear in case that the stored object
> is a file or directory pointer. After calling Clear, the object is not only
> removed from the list but is itself erased? This is not the case with
> TOrdCollection. See example:
> {
> gROOT.Reset();
>
> printf("test TOrdColl..\n");
> fr = new TFile("test.root","recreate");
> TList *list = new TOrdCollection();
> list.Add(fr);
> fr.ls();
> list.Clear();
> fr.ls();
>
> delete list;
> delete fr;
> gROOT.Reset();
>
> printf("\n");
> printf("test TList..\n");
> fr = new TFile("test.root","recreate");
> TList *list = new TList();
> list.Add(fr);
> fr.ls();
> list.Clear();
> fr.ls();
>
> }
> and the output
>
> Enclose multiple statements between { }.
> root [0] .x test.C
> test TOrdColl..
> TFile** test.root
> TFile* test.root
> TFile** test.root
> TFile* test.root
>
> test TList..
> TFile** test.root
> TFile* test.root
>
> *** Break *** segmentation violation
>
> thanks..
> Hajo!
-- Org: CERN, European Laboratory for Particle Physics. Mail: 1211 Geneve 23, Switzerland Phone: +41 22 7679248 E-Mail: Fons.Rademakers@cern.ch Fax: +41 22 7677910