The Default Constructor

ROOT object I/O requires every class to have a default constructor. This default constructor is called whenever an object is being read from a ROOT database. Be sure that you don't allocate any space for embedded pointer objects in the default constructor. This space will be lost (memory leak) while reading in the object. For example:

class T49Event : public TObject {
   Int_t        fId;
   TCollection *fTracks;
   T49Event() { fId = 0; fTrack = new TList; }  // Error space for TList pointer will be lost
   T49Event() { fId = 0; fTrack = 0; }          // Correct default initialization of pointer

The memory will be lost because during reading of the object the pointer will be set to the object it was pointing to at the time the object was written.

Rene Brun, Fons Rademakers
Last update 26/8/96 by FR