Hi,
in my code, I do the following ( TH1D *fHisto[2]; )
TString histNameX = TString("histX_")+fFilenameNoExt;
TString histNameY = TString("histY_")+fFilenameNoExt;
fHisto[kX] = (TH1D*) gROOT->FindObject(histNameX);
fHisto[kY] = (TH1D*) gROOT->FindObject(histNameY);
if (fHisto[kX]) {delete fHisto[kX]; fHisto[kX] = NULL;}
if (fHisto[kY]) {delete fHisto[kY]; fHisto[kY] = NULL;}
cout << "+++ before definition" << endl;
fHisto[kX] = new TH1D(histNameX.Data(), histNameX.Data(),
nCol, static_cast<Double_t>(startCol-1), static_cast<Double_t>(endCol));
fHisto[kY] = new TH1D(histNameY.Data(), histNameY.Data(),
nRow, static_cast<Double_t>(startRow-1), static_cast<Double_t>(endRow));
cout << "+++ after definition" << endl;
i.e., I check with gROOT if my histogram has already been defined, then delete it to make sure there won’t be a memory leak. But ROOT keeps telling me I am producing a memory leak… the above code produces the following output:
+++ before definition
Warning in <TROOT::Append>: Replacing existing TH1: histX_DAQ20090520T125430_0 (Potential memory leak).
Warning in <TROOT::Append>: Replacing existing TH1: histX_DAQ20090520T125430_0 (Potential memory leak).
Warning in <TROOT::Append>: Replacing existing TH1: histX_DAQ20090520T125430_0 (Potential memory leak).
Warning in <TROOT::Append>: Replacing existing TH1: histY_DAQ20090520T125430_0 (Potential memory leak).
Warning in <TROOT::Append>: Replacing existing TH1: histY_DAQ20090520T125430_0 (Potential memory leak).
Warning in <TROOT::Append>: Replacing existing TH1: histY_DAQ20090520T125430_0 (Potential memory leak).
+++ after definition
What am I doing wrong?
Thanks for any advice,
Thomas