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{
TCanvas * cHigh;
TCanvas * cLow;
TFile * f;
RawToSignal * r;
Diagnostics(){f=new TFile("…/rawData/devRUN_3539.root");r=new RawToSignal(f);r->loadTree();
~Diagnostics(){delete f;delete cHigh;delete cLow;}
void showEvent(int ev);


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

for(Int_t stripId=1;stripId<=64;stripId++){
	//TH1F * h=showStripCCF(tmpChip,tmpChan,tmpFec);


}//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.