Memory management and RooWorkspace

Hi,
I have a simple question about memory management and RooWorkspace.
If I import a model to a RooWorkspace does it take ownership of the model and all it’s dependences?
That is, if a delete the RooWorkspace in the end of my function, does it delete all the objects imported to it?
Also, in the case I have bound an external TF1 as a pdf does it take ownership of it?
Many thanks,
Pedro

This forum post is outdated, but still appears if you google for RooWorkspace memory management. A similar question has been answered recently, so this other forum post might be interesting for you:

Direct answers to the questions in this thread:

If I import a model to a RooWorkspace does it take ownership of the model and all it’s dependences?

No, it will not take ownership because like the documentation explains, RooWorkspace::Import clones the model and all the dependencies that are not in the workspace already. Only these clones are owned by the RooWorkspace.

That is, if a delete the RooWorkspace in the end of my function, does it delete all the objects imported to it?

Only the workspace-internal clones are deleted. In other words, if you do workspace.import(*model), you still have to delete model yourself.

Also, in the case I have bound an external TF1 as a pdf does it take ownership of it?

I guess RooTFnBinding was used here, in which case the answer is “no” because the RooTFnBinding doesn’t own the TF1. Actually, this means that models with the RooTFnBinding are not supported by the RooWorkspace. To support it, one would have to override RooAbsArg::importWorkspaceHook in RooTFnBinding, and in this hook create a clone of the TF1 that is imported to the workspace as a generic object. The imported RooTFnBinding also needs to be reset in the hook to point to the imported clone.

But probably it’s not a big deal that this is not supported, as RooGenericPdf is preferred over wrapping an external TF1.