I am generating a lot of RooDataSets in a loop using the same pointer which I am creating at the start and deleting it at the end of the loop. In the meantime I want to write the RooDataSet into a TFile, however when I write the object into the file and then I am deleting the pointer my program is crashing. If I do the same loop but instead of storing RooDataSets I store TH1F pointers is working. Is there a way where I can create the RooDataSets and avoid keeping them in memory while my program is executing? Thanks.