Replace the line
f->Write(); by
f->Write();
t->Write(TObject::kWriteDelete); for more info, see the doc of TObject::Write
t->Write(TObject::kWriteDelete);
Rene