Dear ROOT users and developers,
I am curious about the following code of TH1::Build():
if (fgAddDirectory && gDirectory) {
if (!gDirectory->GetList()) {
Warning("Build","Current directory is not a valid directory");
return;
}
TH1 *hold = (TH1*)gDirectory->GetList()->FindObject(GetName());
if (hold) {
Warning("Build","Replacing existing histogram: %s (Potential memory leak).",GetName());
gDirectory->GetList()->Remove(hold);
hold->SetDirectory(0);
// delete hold;
}
gDirectory->Append(this);
fDirectory = gDirectory;
}
I am wondering why the delete statement is disabled.
When we create histograms in a named script, to save the memory, we have to delete them by hand every time before executing the script again.
We can put a code like gDirectory->Get(“histoname”)->Delete(); in the script ahead of the histogram definition, but it is troublesome to write this for all of a large number of histogram.
Be generous with your life.
Satoru KAMEOKA