Re: [ROOT] on whether to delete root objects

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Nov 01 2001 - 11:38:49 MET


Hi Thomas,

As I said in a mail early today, this bit of code below will work but
is not recommended. The collection classes in ROOT do not delete an object
in a list if the object is not in the heap.
However, the algorithm to detect if an object is on the heap or stack
is not guaranteed to work on all machines/systems or future versions
of compilers. That is why, we would like to discourage this kind of constructs.

Rene Brun

Thomas Bretz wrote:
> 
> Hi Rene,
> 
> does this mean, that:
> 
> {
> TList *list = new TList;
> MyClass a;
> MyClass *b = new MyClass;
> list.Add(&a);
> list.Add(b);
> list->SetOwner();
> [...]
> delete list;
> }
> 
> is correct code and does no segfault?
> 
> Regards,
> Thomas.
> 
> > With
> >  - MyClass *c = new MyClass(); c is on the heap
> >  - MyClass c;  c is in the stack
> >
> > > Something I never understood... When is a object 'on the heap'?



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:05 MET