[ROOT] on whether to delete root objects

From: Isard_Dunietz (dunietz@fnal.gov)
Date: Thu Nov 01 2001 - 06:09:53 MET


// Is the following code fragment reasonable, when one is not sure whether
// an object was newed or not:

TH1F hist( "hist", "",...);
bool condition = ...;
TH1F * histPtr( condition ? new TH1F(...): &hist );

// use histPtr as much as needed

//Once done with histPtr, maybe the easiest to do is just to say
if ( histPtr->IsOnHeap() )
   delete histPtr;
// else histPtr not on the heap and we are fine as the dtor will take of
// it automatically


         Thank you for your advice.  Best, Isi



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:05 MET