Consider this example:
TFile *file = TFile::Open("file.root", "READ");
TH1 * h = (TH1*) file -> Get("histo");
If I would like to remove this histogram from the heap memory is it sufficient to do:
h -> Delete();
h = nullptr;
Please read tips for efficient and successful posting and posting code
ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided
Hi,
yes that should be enough, or even just delete h
.
Cheers,
Enrico
what is the main difference between
delete h
and
h -> Delete()
I don’t think there is any difference in practice if the object is on the heap, @pcanal @Axel ?
If the object is on the stack, ->Delete()
should still be safe (and a no-op), while you can’t call delete
on a stack-allocated object.
Axel
5
Please just use delete h
which works for any heap-allocated object, like those read from a TFile
.
system
Closed
6
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.