Dear ROOT experts!
Suppose I have something like this:
TH1F hist = (TH1F)someAppropriateObject->Clone();
should I always use “delete hist” in order to avoid memory leak?
Regards
defo900
Dear ROOT experts!
Suppose I have something like this:
TH1F hist = (TH1F)someAppropriateObject->Clone();
should I always use “delete hist” in order to avoid memory leak?
Regards
defo900
Hi,
for histograms, it depends if you rely on the ROOT memory management or not. You can learn more about it here: root.cern.ch/root/htmldoc/guide … -directory .
Cheers,
Danilo
Dear Danilo
Thank you for answer.
If I understand correctly when I use clang for my script run I should not write “delete hist”. However when I compile script using g++ then I should write “delete hist”.
Is that correct?
Regards
defo900
Hi,
No - ROOT behaves the same whether interpreted or compiled. And it’s always safe to delete the histogram - but you might not need it if it’s added to the current directory, which is ROOT’s default behavior, see TH1::AddDirectory() root.cern.ch/doc/master/classTH … d7e0f82614
Cheers, Axel.
Dear Axel
Now I have understood. Thanks.
Regards
defo900