temp->Reset();
temp->Delete();
temp->Clear();
do “delete temp;” This has nothing to do with elegance but with avoiding a memory leak. So be thankful that ROOT prints that message - actually it should have made you wonder whether you’re doing something wrong. That’s what it’s for.
Thanks for your quick reply, but I tried that before ! (Yes, I know that if you create a pointer it is necesary to delete it after)
This is my code:
....
TH1D *VdfitC1 = NULL;
....
if(!VdfitR){
for (int i = 0; i<4; i++){
.............
bins = 30+ (i*20);
//the objets--------------------------------------------
VdfitC1 = new TH1D("Vdfit" ,";Vd [cm/#mus];packs",bins,vlow,vup);
.......
//Filling the histo -------------------
for(Int_t i= 0 ;i< t ;i++){
if (i >0)
entry->Clear();
if (tree->GetEvent(i+BPP)<0){
cout << "error reading event !" << endl;
continue;
}
Vdc[i] = entry->getVdc();
VdfitC1->Fill(Vdc[i]);
}
......
// only to indicate which things I tried ;)
VdfitC1->Reset();
....
VdfitC1->Delete();
....
VdfitC1->Clear();
....
VdfitC1->SetDirectory(0);
..............
delete VdfitC1;
}
gDirectory->GetList()->Delete();
}
........
That is, I’m reading a member of an object (t times) stored in a ROOT tree, and filling the histogram in different ways and different ranges with this info.
It works but as you said I think that if I create and destroy let’s say… 1000 histos… I will have “memory” problems.
That’s why I want to declare only one histo that will be filled 1000 times. After my tests using a " TStopwatch" object and 20 histos, this option (declare one object and use it 1000 times) seems to be a 10% faster, but it prints this message.
This " Reset", “Delete” , “Clear” and so on were to indicate what I tried.
Well…
It was my fault. Next time I will try to explain my problem better
uh, OK, but then you still should not use Reset with new. Reset goes well with GetXaxis()->SetNbins() etc; new needs a delete. You could create a new TH1 onceoutside your loops, and then within your loops just re-initialize it using VdfitC1->Reset(), VdfitC1->SetName(), VdfitC1->GetXaxis()->SetNbins() etc.