name for histograms

From: OKUMURA, Akira <oxon_at_icrr.u-tokyo.ac.jp>
Date: Thu, 15 Jun 2006 12:55:27 +0900


Hello ROOTers,

If I make a class which has histogram as a member as below, at the line of declaration of 'MyClass b' ROOT warns 'Potential memory leak'.

class MyClass : public TObject {
private:

   TH1D hist;
   /* other members */
public:

   MyClass() : TObject() {hist = TH1D(0, 0, 1, 0, 1);}    /* other functions */
};

void test()
{

   MyClass a;
   MyClass b; // => says "potential memory leak }

I understand why it happens and that the solution which avoids this is to specify identical name for each histograms. For example, I can give them identical names through arguments for a constructor. However if MyClass has many histograms and they need to be initialize in the default constructor, the default constructor will become messy.

MyClass(const char* name1, const char* name2, /*continue*/) : TObject()
{

   hist1 = TH1D(name1, name1, 1, 0, 1);
   hist2 = TH1D(name2, name2, 1, 0, 1);
   // continue
}

I would like to know how do you implement your application in this case. Is there any standard method ?

Sincerely,

OKUMURA, Akira oxon_at_icrr.u-tokyo.ac.jp
Institute for Cosmic Ray Research, University of Tokyo 5-1-5 Kashiwanoha Kashiwa Chiba 277-8582 Japan Phone/Fax : +81 4-7136-3153
Skype : okumura.akira Received on Thu Jun 15 2006 - 05:56:07 MEST

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:31:59 MET