Memory leak getting TH2Ds from file

Hi ROOTers,

Below is a portion of code I am using to get TH2D objects from a root file and then save as png images. The images are created as I want, but when going through this loop more and more memory is getting used. Any ideas why this could cause a memory leak, as it looks like I should be deleting all the appropriate pointers!

Thanks

Matt

[code]char POL[1];
char fileName[FILENAME_MAX];
char headerName[FILENAME_MAX];
char graphName[FILENAME_MAX];
char saveName[FILENAME_MAX];

sprintf(fileName,"/unix/anita2/mottram/outputSpectra/run%d.root",run);
TFile *input = new TFile(fileName);

sprintf(headerName,"/unix/anita1/newRootData/run%d/timedHeadFile%d.root",run,run);
TFile *fpHead = new TFile(headerName);
TTree headTree = (TTree) fpHead->Get(“headTree”);
TLeaf *triggerTime = headTree->GetLeaf(“triggerTime”);

UInt_t numEntries=headTree->GetEntries();

triggerTime->GetBranch()->GetEntry(0);
Int_t timeI = static_cast<Int_t>(triggerTime->GetValue());

triggerTime->GetBranch()->GetEntry(numEntries-1);
Int_t timeF = static_cast<Int_t>(triggerTime->GetValue());

Int_t numGraphs;
numGraphs = (timeF-timeI)/(3600*6)+1;

TCanvas *c1 = new TCanvas(“c1”,“c1”,400,200);

for(Int_t i=0;i<numGraphs;i++){

for(Int_t ant=1;ant<33;ant++){
  for(Int_t pol=0;pol<2;pol++){

if(pol==0) sprintf(POL,"V");
else sprintf(POL,"H");

sprintf(graphName,"singleHistA%d%c_%d",ant,POL[0],i);

    TH2D *hr = (TH2D*)input->Get(graphName);

//to ensure the 0 values in the last histos don't have an effect on the scale
if(i==numGraphs-1) hr->SetMaximum(-120);
 
gStyle->SetPalette(1);
    hr->Draw("colz");

sprintf(saveName,"/unix/www/users/mottram/public_html/powerSpectra/run%d/singleHistA%d%c_%d.png",run,ant,POL[0],i);

c1->Print(saveName,"png");
c1->Clear();
delete hr;
  }
}

}

delete c1;[/code]

Can you provide a macro I can execute ? The one you posted has several references to external files or directory paths…