void testWriteArray(){ TObjArray *array = new TObjArray(10); array->SetOwner(); // TH1F *h = new TH1F(); for (Int_t i = 0;i<10;i++){ TH1F *h = new TH1F(); TString Name=Form("Histo%02i",i); h->Reset(); // useful if new is outside h->SetName(Name); h->SetTitle(Name); h->SetBins(10,10*i,10*(i+1)); for (Int_t j=0;j<10;j++){ h->Fill(10*i+j); // different histos to see what I get in the output } array->AddAt(h,i); //delete h; //h=0x0; } TH1F *h1 = (TH1F*)array->At(0); cout << " name h1 = " << h1->GetName() << endl; cout << " name h = " << h->GetName() << endl; // still there, sure TFile *file = new TFile("testWriteArray.root","RECREATE"); array->Write("array",TObject::kSingleKey); file->Close(); delete file; file = 0x0; array->Clear(); //cout << " name h = " << h->GetName() << endl; // of course, does not // work if Clear is used return; }