Ownership

From: James Patrick Burke <phjpb_at_slac.stanford.edu>
Date: Thu, 7 Oct 2010 22:05:41 -0700

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:05:48 CEST

This archive was generated by hypermail 2.2.0 : Fri Oct 08 2010 - 11:50:02 CEST