Re: [ROOT] Why "//->" without "+"?

From: Rene Brun (Rene.Brun@cern.ch)
Date: Wed Jun 27 2001 - 09:03:18 MEST


Hi George,

Suppose a class Event with  members like
 TClonesArray *fArray1;  //->
 TClonesArray *fArray2   //
 TObjArray    *fArray3;  //->

If you have declared Event+ in the pragma statement of LinkDef.h, then
the automatic Streamer will behave like the following code in the old versions:
(eg writing part)
  fArray1->Streamer(buffer);
  buffer << fArray2;
  fArray3->Streamer(buffer);

Specifying "->" in the comment field instructs the system that it can assume
that the pointer is always non null. This speeds up I/O.
When in read mode, the fArray1 and fArray3 objects must exists.
the fArray2 will be always recreated at each read. It means that in your
Event destructor, you must take care of deleting any previous object pointed
by fArray2. However, in case you have specify SetAutoDelete(kFALSE) for
the top branch Event, the destructor of Event is not called (you gain time).
In this case, you must have a Clean method called before the next input
operation to delete fArray2.
My guess is that you have SetAutoDelete(kFALSE) and in this case you will see
a leak if you do not Clean your Event independently if you specify "+" or not
in LinkDef.

We have hesitated to make the "+" option the default. We decided to make it
optional until most users have tested and converted to the new scheme.

We strongly suggest to always use the "+" option and also the branch function
SetAutoDelete(kFALSE). We will certainly make these two options the default
in future versions.

Rene Brun

George Irwin wrote:
> 
> Hi,  We are seeing a memory leak in old code which used to
> work.  The leak goes away when I add "//->" as in Event.h.
> The ROOT documentation, and the Event.h example, suggests
> that "//->" should now be used to flag the declarations of
> pointers-to-TClonesArrays which the user guarantees to be
> valid pointers to static objects.  This is to prevent the
> automatic streamer from creating a new TClonesArray when each
> new event is read.  The user manual and roottalk item 2004 says
> that "//->" is only needed when the user has turned on automatic
> streamers with a "+" affixed to the end of the pragma statement
> of the LinkDef.h file.  But we are finding that we need the
> "//->" for TClonesArrays declared in classes without "+".
> Even classes with manual streamers ("-" instead of "+") need
> "//->" to prevent multiple instantiations.  So my question is
> whether it is normal to be getting automatic streamer behavior
> without the "+".  An auxiliary question is whether "+" will
> someday become the default so that users do not need to put
> it on the pragma line.  Perhaps we are seeing such default
> behavior already.  I am using the ROOT CVS head release
> on RedHat Linux 6.2 with egcs.1.1.2.  Thanks.  George



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