Running the same file: about reseting root

Hi guys
I have a quick question. I am running the same file over and over again and I get to the same harmless warnings. Is there a way to reset ROOT so this warnings stop showing off?
It seems I should be calling the destructor of the TH1 or maybe I should be empting the memory after each run?
I really appreciate any comments.
Note: My first line in my file is gROOT->Reset(); I was hoping this was going to solve this issue but it did not do anything.

root>> .x peakFit.C
Note: File “fcntl.h” already loaded
[…] //load all my data
Warning in TH1::Build: Replacing existing histogram: h1 (Potential memory leak)

Hi,

can you post a macro that shows an error message like “Note: File “fcntl.h” already loaded”, so we can reproduce it?

The other warning message can be avoided by using “delete gROOT->FindObject(“h1”)” before you create a new one with the same name.

Axel.

This is what happens with the “fcntl.h” message. I have attached the code to see if you get the same error. Thank you,
Cristian

root [4] .x peakfit.C
Note: File “fcntl.h” already loaded
filename: fakedata
Warning in TH1::Build: Replacing existing histogram: h1 (Potential memory leak).
root [5]

The fakedata file is just a text file with integer data organize in either row or columns separated by spaces.


{

/* This Macro Creates a Histogram
of Type TH1I (integers) by reading
as input ascii text files containing
two columns: CHANNEL/COUNTS

--------------------------------------*/

gROOT->Reset();

//SYSTEM include files

//ROOT include files
#include <fcntl.h>
#include <TSpectrum.h>
#include <TPolyMarker.h>
#include <TMath.h>
#include <TAxis.h>
#include <TStyle.h>
#include <TAttLine.h>
#include <TH1.h>

//DEFINES for the program
#define MAX_COL 8;
#define MAX_MCA 16384;

/----------------------------------------------
VARIABLES FOR READING ASCII DATA
------------------------------------------------
/
const char *filename = new char [50];
FILE *fp;
int ptmp;
int i=0, nbins;
int buffer[MAX_MCA]; //nbins <= MAX_MCA

/--------------------------------------
GET FILENAME
----------------------------------------
/
printf("%s",“filename: “);
scanf(”%s”, filename);
if ((fp = fopen(filename,“r”)) == NULL)
printf("%s", “File not found!\n”);

/*-------------------------------------------------
READ FILE AND WRITE INTO buffer ARRAY
---------------------------------------------------
/
nbins=0;
while ( fscanf(fp,"%d",&ptmp) != EOF )
buffer[nbins++] = ptmp;

//--------------------------------------//
//FILL HISTOGRAM *h1 WITH *buffer
//--------------------------------------//
TH1I *h1 = new TH1I(“h1”,"",nbins,0,nbins);
for(i=0;i<nbins;i++)h1->SetBinContent(i+1,buffer[i]);

xaxis = h1->GetXaxis();
xaxis->SetTitle(“Channel”);
xaxis->CenterTitle();
yaxis = h1->GetYaxis();
yaxis->SetTitle(“Relative Counts”);
yaxis->CenterTitle();

TCanvas *S = new TCanvas(“S”,“Spectra”,6);
S.SetLogy();
h1->Draw();

}

[quote=“Axel”]Hi,

can you post a macro that shows an error message like “Note: File “fcntl.h” already loaded”, so we can reproduce it?

The other warning message can be avoided by using “delete gROOT->FindObject(“h1”)” before you create a new one with the same name.

Axel.[/quote]

Axel
I do not have any of the warning messages anymore. Everything seem to be solved after I add the line
delete gROOT->FindObject(“h1”);
Is there anyother way of doing this? I do not like the idea of deleting at object just when my program begins executing. What if there is another object from other adjacent code with the same name, or what if the object does not exist in the first place? Putting that line at the beginnin of the program makes it look like aI am killing a phantom that “might be there”. Is there any other way to remove the object as soon as I stop/quit my macro?
Cristian