Re: [ROOT] gROOT->Reset() behaviour

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Oct 03 2000 - 15:37:22 MEST


Hi Damir,

gROOT->Reset() is useful at the beginning of an unnamed script that you want
to execute multiple times. Because variables defined in an unnamed script
are in the global scope, one must delete variables created by previous
executions.
This works nicely if you execute simple scripts.
With more complex scripts, it is strongly recommended to always use
named scripts. In this case, it is not necessary to call gROOT->Reset(),
the cleanup being automatic when the script terminates its execution.
In summary, you gROOT->Reset in
// script simple1.C
 {
    gROOT->Reset();
    int i=9;
    float x = 7.8;
    ...
 }

not necessary in
// script simple2.C
  void simple2()
{
   int i = 9;
   float x = 9.8;
   ..
}

After execution of simple1.C, all variables created in the script still
are visible in the global scope. At the next call to simple1.C, the previous
variables/objects created in the global scope will be deleted by gROOT->Reset().

After execution of simple2.C, this is not necessary, variables local to
simple2.C
are automatically deleted. Only objects created via new in simple2.C
continue to exist.

Rene Brun


Damir Buskulic wrote:
> 
> Hi,
> 
> That's why I was confused. Obviously, I still lack this course...
> Anyway, even if I perfectly understand why it's impossible to change
> this behaviour, it is annoying to have a strongly suggested way of
> cleaning the interpreter environment, when in fact the user himself has
> to clean some of the objects he created. I know it is basic programming
> practice but in the interactive session, this may be a problem.
> Imagine you create several histograms interactively via new, you will
> not be able to work a few hours without restarting your machine because
> you (in fact I) fill the memory little by little. I know I should build
> static objects instead of using new but every small script uses new. And
> executing again and again such small scripts does exactly the symptoms
> above if one is too lazy to think absolutely every time to delete his
> heap objects at the end of his script.
> Well, Is it really impossible, or is it going to slow down the
> interpreter to take care of the objects allocated via new and be able to
> clean completely the memory. This is certainly not the way a C compiler
> works but it would ease the everyday use. There are certainly obvious
> cases I miss where this is not applicable. Which ones ?
> 
> Sorry if all this discussion is like going back in time but I think
> these simple cases make some people feeling uneasy about the
> interpreter, when they were used not to bother about pointers, memory
> and so on. I think it's really a matter of user friendlyness.
> 
> Cheers
> 
> Damir
> 
> Paul Balm wrote:
> >
> > Hi!
> >
> > You'll probably get a lot more educated asnwer from somebody else on the
> > list, but at least I'm quick.
> > I'm very new to ROOT, so I still remember things from my course. :-)
> > gROOT->Reset() clears objects created on the stack, and as you know, the
> > operator new creates an object on the heap.
> > I hope I remember correctly, but it looks like that's the problem. Enter a
> > line
> > delete vd;
> > in the destructor of the class that's creating this object. That should
> > help.
> > Cheers,
> >
> > Paul
> >
> > Damir Buskulic wrote:
> >
> > > Hi,
> > >
> > > I know this ubject has been discussed many times but I'm a little bit
> > > confused by the behaviour of gROOT->Reset(). It is supposed to clean all
> > > global variables in the interpreter environment. But when I build a new
> > > object of mine :
> > > vd = new VFrDataBase("demoDB.root")
> > > and issue a gROOT->Reset() after this, for example by running a script
> > > containing gROOT->Reset() as the first line, a few times, it is obvious
> > > that the object vd, though removed from the interpreter environment, and
> > > though global, is not deleted. The memory is not freed and everything
> > > happens as if there was a memory leak.
> > > What is happening ? When is an object effectively deleted by a
> > > gROOT->Reset() ?
> > > I do understand the necessity to not delete some objects (such as a
> > > Canvas for example) but how do I specify that an object can be deleted ?
> > > I tried SetBit(kCanDelete) to no avail.
> > >
> > > Any explanations/hints ?
> > >
> > > Cheers
> > >
> > > Damir
> > > --
> > > =====================================================================
> > > | Damir Buskulic                  | Universite de Savoie/LAPP       |
> > > |                                 | Chemin de Bellevue, B.P. 110    |
> > > | Tel : +33 (0)450091600          | F-74941 Annecy-le-Vieux Cedex   |
> > > | e-mail: buskulic@lapp.in2p3.fr  | FRANCE                          |
> > > =====================================================================
> > > mailto:buskulic@lapp.in2p3.fr
> >
> >   ------------------------------------------------------------------------
> >
> >   Paul Balm <p.balm@nikhef.nl>
> >   Fermilab (NIKHEF)
> >   DZero
> >
> >   Paul Balm
> >   Fermilab (NIKHEF)  <p.balm@nikhef.nl>
> >   DZero
> >   PO Box 500         Fax: ++ 1 630 840 8886
> >   Batavia            Home: ++ 1 630 933 8857
> >   IL                 Work: ++ 1 630 840 2177
> >   60510
> >   USA
> >   Additional Information:
> >   Last Name       Balm
> >   First Name      Paul
> >   Version         2.1
> 
> --
> =====================================================================
> | Damir Buskulic                  | Universite de Savoie/LAPP       |
> |                                 | Chemin de Bellevue, B.P. 110    |
> | Tel : +33 (0)450091600          | F-74941 Annecy-le-Vieux Cedex   |
> | e-mail: buskulic@lapp.in2p3.fr  | FRANCE                          |
> =====================================================================
> mailto:buskulic@lapp.in2p3.fr



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:34 MET