Warning in <TROOT::Append>: Replacing existing TH1: Radiance_31 (Potential memory leak)


I have a program to create TH2D histograms for some Radiance data, but I always get these warning messages when running the code from the second time.

I tried inserting gROOT->Reset(); on the beginning of the code, but I still get these warning messages.

All the Histograms are created with no further errors, but I’m afraid I could get errors on the results from the memory leak. :confused:

Thanks a lot.

At the beginning of your code, you can put:

delete gROOT->FindObject("Radiance_31");

for each object that you are overwriting when rerunning your script.

To automatize, you could try also:

TSeqCollection* canvases = gROOT->GetListOfCanvases();
TIter next(gROOT->GetListOfCanvases());
while(c = (TCanvas*)next())
	delete c;

Try something like this: TH2D *h = (TH2D *)gROOT->FindObject("Radiance_31"); // gROOT or gDirectory delete h; // delete the old histogram (if found) h = new TH2D("Radiance_31", "Radiance 31", ...); // create the new one

Thank you for both answers.

I tried both of the solutions. I could run the code twice with no warnings. But always on the third run I get the same error:

root [2] .x Solar_Radiance.C
!!!Fatal Error: Interpreter memory overwritten by illegal access.!!!
!!!Terminate session!!!

On the beginning of the code I tried like ferhue advised me:

void Solar_Radiance(){


// Delete Objects
delete gROOT->FindObject("Radiance_31");
delete gROOT->FindObject("Radiance_32");
delete gROOT->FindObject("Radiance_33");

And later as Pepe Le Pew:

Reflectance1 = 1.;
cout<<"Please, choose the Local Time [hours (0,24)]: ";

    TCanvas *c1 = new TCanvas("c1");
    legend = sprintf(buffer,"Solar Radiances (Local Time=%.1f hours);Days Of the Year;Latitude [deg]",Hour1);
    TH2D *h = (TH2D *)gROOT->FindObject("Radiance_31");
    delete h;
    TH2D *Histo_Rad31 = new TH2D("Radiance_31",buffer,num_days,1.,365.,num_latitudes,-90.,90.);
    for(int N=0;N<num_days;N++){
      for(int a=0;a<num_latitudes;a++){
        Radiance_31[N][a] = Is*Reflectance1*Radiance[N][Hour1][a];

For both solutions I get this catastrofic error :frowning:

Thank you again.


Remove “gROOT->Reset();” completely.
What are the definitions of “legend”, “buffer”, “Radiance_31”, “Radiance”, “Days”, “Latitudes”?
Try: / ... TCanvas *c1 = (TCanvas *)gROOT->GetListOfCanvases()->FindObject("c1"); delete c1; c1 = new TCanvas("c1"); // ... TH2D *Histo_Rad31 = (TH2D *)gROOT->FindObject("Radiance_31"); delete Histo_Rad31; Histo_Rad31 = new TH2D("Radiance_31", buffer, num_days, 1., 365., num_latitudes, -90., 90.); // ... BTW. Apparently you create a histogram with the “Radiance_31” name but you also have a two-dimensional array “Radiance_31”.

Oh, it worked now!!

It seems the problems was exactly that: I named both the histogram and the array with the same name :confused:

For your information. I’m defining a space optical system, and for that I need to define the radiance for a given latitude, local time and day of the year.

The legend and buffer variables are set when I choose a particular local time, and then I fill a 2D Histogram with the latitude, day of the year and radiance.

Thank you again! Next time I’ll be more careful when naming variables.

Best Regards.