Re: [ROOT] Another Problem with TObjArray (v3.02.00-Win32)

From: Fons Rademakers (Fons.Rademakers@cern.ch)
Date: Thu Apr 11 2002 - 01:46:19 MEST


Hi Peter,

  this is not a Win32 problem. It fails everywhere but only when the
code is run in CINT. The problem is that CINT creates all objects on the
heap (the real system heap) also the objects that are declared in CINT
as stack objects and which it therefore deletes as soon as they go out
of scope. The TObjArray::Delete() is correct, but I need to fix the
IsOnHeap() to return false in case the object is a CINT stack object to
avoid double deletion, which is the cause of your crashes.

As soon as Masa is back online we will come with a fix.
For the time being don't put stack objects in containers in CINT.


Cheers, Fons.



On Thu, 2002-04-11 at 01:00, Peter Lipa wrote:
> Hi rooters,
> I don't know if David Chamont's problem is related to the following, but
> this is
> what we found:
> 
> In the win32 root v.3.02.00 version, the deletion of TObjArray owned objects
> does not seem to
> work correctly. The doc and the intent of the  TObjArray::Delete() function
> is to delete
> all HEAP based objects and set fCont[i]=0 for all deleted objects and also
> for all STACK based objects;
> 
> To do that, IMHO the fCont[i] needs to be outside the if(...IsOnHeap())
> statement as suggested 
> below:  
> 
> 
> //__________________________________________________________________________
> ____
> void TObjArray::Delete(Option_t *)
> {
> // Remove all objects from the array AND delete all heap based objects.
>     for (Int_t i = 0; i < fSize; i++) {
>         if (fCont[i] && fCont[i]->IsOnHeap()) {
>             TCollection::GarbageCollect(fCont[i]);
>             //fCont[i] = 0; // tkp nlx 4/5/02 commented out intentionally
>         }
>         fCont[i] = 0; // tkp nlx 4/5/02 moved outside the loop to remove ALL
> objects
>     }
> Init(fSize, fLowerBound);
> }
> 
> 
> HOWEVER, the real problem is that in CINT (on win32) the TObject::IsOnHeap()
> ALWAYS returns true
> both for heap and stack objects as demonstrated by the testmacro
> TObjArrayTest_roottalk.C calling TObjArray::Delete() in the attachment.
> CINT crashes if this macro is run twice (and can't recover).
> 
> I did not test this on other platforms. Is it possible that
> TObject::IsOnHeap() does not work at all on Win32 platforms (or do I just
> not understand it's supposed purpose)? But then there is no way to safely
> delete mixed collections on windows?!?
> 
> 
> What to do?
> Thanks.
> 
> Peter
>  
> 
-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers@cern.ch              Phone: +41 22 7679248
WWW:    http://root.cern.ch/~rdm/            Fax:   +41 22 7679480



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:49 MET