ROOT Version: Not Provided Platform: Not Provided Compiler: Not Provided
The following snippets are adapted from the Manual.
I created an empty file.root and ran the following.
void ownership() {
TFile myFile("file.root");
TH1F * h1 = new TH1F("h1","Histogram from a Gaussian",100,-3,3);
h1->FillRandom("gaus",10000);
h1->Draw();
}
I saw a blank canvas as promised. My guess is that h1 automatically got owned by myFile, so at the end of the scope h1 was deleted. Cool.
What I am curious about is the ownership of h1 if I created it on the stack
void ownership() {
TFile myFile("file.root");
TH1F h1("h1","Histogram from a Gaussian",100,-3,3);
h1.FillRandom("gaus",10000);
h1.Draw();
}
My questions are:
Who owns h1 in this case?
I still see a blank canvas, but is that because h1 âowns itselfâ (I actually dunno what Iâm talking about here, please forgive the ignorance) and goes out of scope when we reach }, or because h1 still gets automatically owned by myFile when we reach }?
Thanks!
I guess I donât really know what is meant by ownership here.
Does it make sense to talk about ownership when it comes to something created on the stack?
As in, if h is created on the stack, can it be owned by anyone?