Re: Ownership

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Fri, 8 Oct 2010 07:43:07 +0200


  Hi Jim,

If you do not understand the Object Ownership chapter (::), I suggest to add

      TH1::AddDirectory(kFALSE) at the beginning of your script or session. After this call, it is up to you to manage your histograms and delete them when appropriate.

Rene Brun

On 08/10/2010 07:05, James Patrick Burke wrote:
>
> ROOT version: 5.26/00
> Machine: MacBook (intel), Mac OS X (10.5.8)
>
> Hello,
>
> I have, in my code, a function containing the lines:
>
> TH1* h_data = data_->createHistogram("h_data",*x_,Binning(numBins_));
> TH1* h_func = pdf->createHistogram("h_func",*x_,Binning(numBins_));
>
> (data_ is a RooDataSet*, pdf is a RooGaussian*, x_ is a RooRealVar*).
>
> If I call this function more than once I get the warning
>
> Warning in <TROOT::Append>: Replacing existing TH1:
> h_data__numDegDaysBranch (Potential memory leak).
> Warning in <TROOT::Append>: Replacing existing TH1:
> h_func__numDegDaysBranch (Potential memory leak).
>
> when running.
>
> I believe RooAbsReal::createHistogram(...) is the method being called,
> and from
> http://root.cern.ch/root/html/RooAbsReal.html#RooAbsReal:createHistogram%2,
> I'm told "The caller takes ownership of the returned histogram".
>
> Does this mean that I take ownership, or my data_ and pdf objects take
> ownership?
>
> Either way, I want to avoid a memory leak and so should presumably
> call delete somewhere.
>
> (I'd prefer not to delete data_ and pdf.)
>
> I've read Chapter 8 (Object Ownership) of the Users Guide, but I'm
> afraid I don't really follow it :-(
>
> If somebody could point out how I can avoid this memory leak, I'd be
> very much obliged.
>
> (Would simply varying the first argument ("h_data" or "h_func", above)
> of createHistogram() every time I call my function do the trick?)
>
> Sincerely,
>
> Jim.
>
>
Received on Fri Oct 08 2010 - 07:43:15 CEST

This archive was generated by hypermail 2.2.0 : Sat Oct 09 2010 - 05:50:02 CEST