Re: Who's responsible for deletion?

From: Rene Brun (Rene.Brun@cern.ch)
Date: Mon Sep 14 1998 - 15:32:19 MEST


Patrick Schemitz wrote:
> 
> Hi Rooter,
> 
> > Patrick Schemitz wrote:
> > [...]
> >
> > > In compiled code (using ROOT classes), using operator delete on
> > > instances of ROOT classes sometimes causes a segfault later on.
> > > (Of course I don't use the pointer after "delete", but nonetheless
> > > the program dumps core. And of course I don't use delete on
> > > automatic variables.)
> > >
> > > Omitting the deletion of dynamic instances of ROOT classes (TBRIK
> > > comes to my mind) seems _not_ to lead to a memory leak - how come?
> >
> > [....]
> >
> > Patrick,
> > When you invoke the constructor for many Root objects, such as
> > histograms, Trees, materials, Nodes, these objects are automatically
> > added to some containers.
> > In the case of TMaterial, these objects are added to the list
> > of materials for the current geometry.
> > When you will delete the geometry object, all materials in this
> > geometry will be deleted.
> 
> I see, but why the core dumps when using delete on these objects?
> Doesn't the destructor remove them from the containers?

yes, the destructor removes them from their container.
If you delete the geometry object, you should not delete (twice)
the material.
I do not know what happens in your case. Very likely you delete
a material, but this material is still referenced by another node
in the geometry tree.

Rene Brun



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:37 MET