> Hi Christoph,
>
> what I do in situations like this is something like this:
>
> ----------------------------------------------------------------
>
> in my main program:
>
> ----------------------------------------------------------------
> [...]
> TList *gc = new TList; // list keeping track of objects to be deleted
> A* x = new A;
> A* y = new A( x, 0 );
> A* z = new A( 0, x );
> A* a = new A( y, z );
> gc->Add(x); gc->Add(y); gc->Add(z); gc->Add(a);
> [...]
> tree->Branch("Aname","A", &a, 10000, 0 );
> [...]
> gc->Delete(); // delete objects when done
> ----------------------------------------------------------------
[...]
Hi,
yes, I have it working now. I adapted my old garbage collection to the
simple example and it works. Maybe this is of a certain interest for
some people:
I have a class called GarbageCollection. It has only a static data member
namely a THashTable to store the entries to be deleted. The classes, which
want to use it, provide the function Clear, which calls the only public
member function:
void A::Clear( Option_t * )
{
GarbageCollection::garbageCollect( this );
}
The collection function uses the ROOT run-time type information to find
out the pointers and their accessor functions, looks them up recursively,
and stores them in the THashTable, taking care of not getting double
entries. After that, it deletes the contents of the hash table.
It has the advantage, that the impact on only loosely related code is
minimal. I can use it for my current project with only the small change
in the Clear function.
The drawback could have been foreseen: It slows everything down, for my
`class A' example it is a factor of three! But these hashing things must
be also done by TTree, and I wonder, if I could use any system information
in an TObjectTable to speed things up. I can see by gObjectTable->Print(),
that the system has the missing information.
best regards
Christoph