TObject ownership after writing

Hi,

Reading the chapter about Object Ownership it is not clear to me whether an object is own by the user after it is written in a file. For example:

TFile *f = new TFile("tt.root", "recreate")
TGraph *gr = new TGraph()
gr->SetName("gr")
gr->Write()
f->Close()
delete f
delete gr

Although it does not crash as it would if I replaced TGraph by TH1, is it necessary to delete the object?

Thanks
Bruno

Hi,

The ownership rules depends on the object type. TTree and the histograms (anything inheriting from TH1 like, TH1F, TH1D, TH2D, etc…), TEventList, TEntryList and TGraph2D (but NOT TGraph) are owned by the directory which is the current on at the time they are created. All the other, are owner by the user (by default).

Cheers,
Philippe.