Is deleting a pdf managing deleting the internal RooRealVar?

Let’s suppose we allocate some RooRealVar

RooRealVar *var1=new …

RooRealVar *varN=new …

and allocate a RooAbsPdf *mypdf that uses the previous RooRealVar

when we delete the pdf
delete mypdf
->does it manage to delete the corresponding RooRealVar ?

Should the user manage that by hand ?

Thank you

Hello @escalier,

The user should take care of deleting the objects used by other objects. The main reason is:
If a variable is used by two objects, who should own (and delete) it?

This problem cannot be solved, so nobody owns the objects.

One heuristic you can use is reference vs. pointer, for example for the RooGaussian.

  • If the constructor takes other objects by reference, they are definitely not owned.
  • If the constructor (or some other function) takes something by pointer, it can be both owned and not owned. In this case, the documentation of the function should make it clear, but this is not always the case. :frowning:
  • An RValue reference && would make it clear that it’s definitely owned, but it’s rarely used in RooFit.

Thank you very much Stephan.
Everything is clear.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.