Changes to macro are not taken into account unless ROOT is restarted

Hi,
I am struggling with what I suspect should be a simple problem. But I haven’t found a solution so far.

Here is a simple macro I am working with:

[code]void Newcanvas2()
{
TCanvas *C = new TCanvas(“C”,“canvas”,600,600);

C->SetFillColor(17);
C->SetBorderMode(0);

TH2F *h2 = new TH2F(“h”,“Axes”,20,-10,10,20,-10,10);
h2->Draw(“AXIS”);
TF1 *f1 = new TF1(“f1”,“sin(x)/x”,0,10);
f1->Draw();

}
[/code]

If I run this with [color=#4040FF].X Newcanvas2.C[/color], I get the graph I expect, but if I make a change (such as changing sin to cos or changing the FillColor, the change is not taken into account. I have to log out of ROOT and log in again and then it works as expected.

If it helps, I am working with root-6.06.08 and gcc5.4 on kubuntu 16.04 that I built using the instructions in this thread: Memory leak in ROOT::Math::IntegratorMultiDim

I would appreciate help with this.

ps: This seems similar to me to the problem described in some other threads (for example: Macro loading in root6) . But I thought that a solution had been found to those problems…

I just tried on Mac with the ROOT master (6.09/01) .
I can change the macro and execute within the same ROOT session.
And I see the change.

I just get the warning:

Warning in <TFile::Append>: Replacing existing TH1: h (Potential memory leak).

But that’s normal…

Thank you for testing it! Yes, that is indeed the behaviour I expect and used to get in previous installations.

In fact, I get this problem with something even simpler:

void tmp() { Int_t i=2; cout << i <<endl; }

If I change i to 3, it still prints 2 unless I restart ROOT.

This is the problem someone else presented in that older thread

I also get the problem they got with unnamed macros and gROOT-reset(): redefintion of i

At this point, all I can do is restart ROOT everytime.

No problem for me with ROOT master:

root [0] 
Processing tmp.C...
2
root [1] .x tmp.C
3
root [2] 

Hi,

Yes that was a fairly fundamental bug in ROOT 6.06. As Olivier points out it’s fixed in the master; I’ll check next week whether I can backport the fix - I remember that it was non trivial / fairly intrusive. Still, this one is really annoying. I’ll let you know, please ping me should I forget!

Cheers, Axel.

Thanks Olivier, Axel!

I have ended up installing the master (6.09/01) and indeed the problem has disappeared with it. Up until this point, I hadn’t realised that the master was a separate version. Since it is a development version is it recommended to use it? Is it stable enough to be used with students?

In case it helps anyone else.
I ended up removing the previous version completely and obtained the master source from:

And I built it using the instructions in this thread: viewtopic.php?f=3&t=22150&p=97060#p97010

Thanks again,
Saeeda