How to manage histograms when invoking class functions

Hi everyone, I am relatively new to ROOT and OO programming and I am having difficulties dealing with object ownership and memory related issues.

So I have a class (Diagnostics) that I use to plot some histograms created from another class (RawToSignal). The thing is that since file devRUN_3539.root is loaded in this case all the 64 histograms are stored in this file as OBJ (meaning they are stored there until I close the file?) . So for example if i invoke showEvent 10 times I have 640 histograms in memory in that file. I am not sure what is the best way to deal with this, i would prefer a fast way, it is not so important in this particular case but I need this technique in larger programs too. Maby using some temporary folder or deleting each instance if it is a good idea? please provide me some example code lines. Thanks

class Diagnostics{
private:
TCanvas * cHigh;
TCanvas * cLow;
TFile * f;
RawToSignal * r;
public:
Diagnostics(){f=new TFile("…/rawData/devRUN_3539.root");r=new RawToSignal(f);r->loadTree();
cHigh=0;cLow=0;}
~Diagnostics(){delete f;delete cHigh;delete cLow;}
void showEvent(int ev);

};

void Diagnostics::showEvent(int ev){
r->loadEntry(ev);
if(cHigh) {cHigh=0;}
cHigh=new TCanvas(“High Gain”,“High Gain”);
//TCanvas * cLow=new TCanvas(“Low Gain”,“Low Gain”);
cHigh->Divide(8,8);//cLow->Divide(8,8);

for(Int_t stripId=1;stripId<=64;stripId++){
	r->plotStripH(stripId);
	cHigh->cd(stripId);r->h_strip->SetMaximum(150);r->h_strip->Draw();		
	
	//TH1F * h=showStripCCF(tmpChip,tmpChan,tmpFec);
	//h->SetMaximum(50);		
	//cLow->cd(stripId);h->Draw();
}	

//cLow->Update();cLow->Draw();
cHigh->Update();cHigh->Draw();

}//end of showEvent

I am not sure to understand your question.
If you prefer to do teh memory management yourself, you can call

TH1::AddDirectory(0); before reading your histograms.

see chapter about object ownership in the Users Guide.

Rene