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.
Thanks a lot.
At the beginning of your code, you can put:
for each object that you are overwriting when rerunning your script.
To automatize, you could try also:
TSeqCollection* canvases = gROOT->GetListOfCanvases();
while(c = (TCanvas*)next())
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  .x Solar_Radiance.C
!!!Fatal Error: Interpreter memory overwritten by illegal access.!!!
On the beginning of the code I tried like ferhue advised me:
// Delete Objects
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");
TH2D *Histo_Rad31 = new TH2D("Radiance_31",buffer,num_days,1.,365.,num_latitudes,-90.,90.);
Radiance_31[N][a] = Is*Reflectance1*Radiance[N][Hour1][a];
For both solutions I get this catastrofic error
Thank you again.
Remove “gROOT->Reset();” completely.
What are the definitions of “legend”, “buffer”, “Radiance_31”, “Radiance”, “Days”, “Latitudes”?
TCanvas *c1 = (TCanvas *)gROOT->GetListOfCanvases()->FindObject("c1");
c1 = new TCanvas("c1");
TH2D *Histo_Rad31 = (TH2D *)gROOT->FindObject("Radiance_31");
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
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.