Delete file crash

Hi,

I produced a class with the MakeClass function.

In the Init(TTree tree) I read some histograms from a root file and I store
them into a
vector<TH1D
> refHisto*

In my main; to use this class I just do something like:

  TChain* bckgT = new TChain("TreeB");
  bckgT->AddFile("bckg.root");
  
  TChain* signT = new TChain("TreeS");
  signT->AddFile("sign.root");
    
  //   BCKG
  Boosted *bckg = new Boosted(bckgT);
  bckg->Loop();
  
  // SIGN
  Boosted *sign = new Boosted(signT);
  sign->Loop();

  delete bckg;
  delete sign;

  return 0;

I am compiling it with g++

the first problem is the usual:

Warning in TDirectoryFile::Append: Replacing existing TH1: histo0 (Potential memory leak).

that appears when I call the second constructor but I guess there is nothing I can really do since I am really creating two object with the same
name. They will be stored in a public member of the class so I don’t think I have a memory leak.

The real problem is that it crashes at the end of the main (after the delete sign;) with this error

#10 0x0025e4bd in TString::TString(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () from /afs/cern.ch/atlas/software/releases/17.0.4/LCGCMT/LCGCMT_60d/InstallArea/i686-slc5-gcc43-opt/lib/libCore.so #11 0x002e06b2 in ROOT::TGenericClassInfo::CreateRuleSet(std::vector<ROOT::TSchemaHelper, std::allocator<ROOT::TSchemaHelper> >&, bool) () from /afs/cern.ch/atlas/software/releases/17.0.4/LCGCMT/LCGCMT_60d/InstallArea/i686-slc5-gcc43-opt/lib/libCore.so #12 0x002e0b49 in ROOT::TGenericClassInfo::GetClass() () from /afs/cern.ch/atlas/software/releases/17.0.4/LCGCMT/LCGCMT_60d/InstallArea/i686-slc5-gcc43-opt/lib/libCore.so #13 0x02fa76c4 in TProfile::Class() () from /afs/cern.ch/atlas/software/releases/17.0.4/LCGCMT/LCGCMT_60d/InstallArea/i686-slc5-gcc43-opt/lib/libHist.so #14 0x02dc0c37 in TProfile::IsA() const () from /afs/cern.ch/atlas/software/releases/17.0.4/LCGCMT/LCGCMT_60d/InstallArea/i686-slc5-gcc43-opt/lib/libHist.so #15 0x00238474 in TObject::InheritsFrom(TClass const*) const () from /afs/cern.ch/atlas/software/releases/17.0.4/LCGCMT/LCGCMT_60d/InstallArea/i686-slc5-gcc43-opt/lib/libCore.so #16 0x010270c5 in TDirectoryFile::Save() () from /afs/cern.ch/atlas/software/releases/17.0.4/LCGCMT/LCGCMT_60d/InstallArea/i686-slc5-gcc43-opt/lib/libRIO.so #17 0x0102711b in TDirectoryFile::Save() () from /afs/cern.ch/atlas/software/releases/17.0.4/LCGCMT/LCGCMT_60d/InstallArea/i686-slc5-gcc43-opt/lib/libRIO.so #18 0x0102230b in TDirectoryFile::Close(char const*) () from /afs/cern.ch/atlas/software/releases/17.0.4/LCGCMT/LCGCMT_60d/InstallArea/i686-slc5-gcc43-opt/lib/libRIO.so #19 0x0103e7d4 in TFile::Close(char const*) () from /afs/cern.ch/atlas/software/releases/17.0.4/LCGCMT/LCGCMT_60d/InstallArea/i686-slc5-gcc43-opt/lib/libRIO.so #20 0x0103eb84 in TFile::~TFile() () from /afs/cern.ch/atlas/software/releases/17.0.4/LCGCMT/LCGCMT_60d/InstallArea/i686-slc5-gcc43-opt/lib/libRIO.so #21 0x002a4c2d in TCollection::GarbageCollect(TObject*) () from /afs/cern.ch/atlas/software/releases/17.0.4/LCGCMT/LCGCMT_60d/InstallArea/i686-slc5-gcc43-opt/lib/libCore.so #22 0x002abbd0 in TList::Delete(char const*) () from /afs/cern.ch/atlas/software/releases/17.0.4/LCGCMT/LCGCMT_60d/InstallArea/i686-slc5-gcc43-opt/lib/libCore.so #23 0x00254c81 in TROOT::~TROOT() () from /afs/cern.ch/atlas/software/releases/17.0.4/LCGCMT/LCGCMT_60d/InstallArea/i686-slc5-gcc43-opt/lib/libCore.so #24 0x01a084b9 in __cxa_finalize () from /lib/i686/nosegneg/libc.so.6 #25 0x002020c4 in __do_global_dtors_aux () from /afs/cern.ch/atlas/software/releases/17.0.4/LCGCMT/LCGCMT_60d/InstallArea/i686-slc5-gcc43-opt/lib/libCore.so #26 0x0068d810 in _fini () from /afs/cern.ch/atlas/software/releases/17.0.4/LCGCMT/LCGCMT_60d/InstallArea/i686-slc5-gcc43-opt/lib/libCore.so #27 0x0098a956 in _dl_fini () from /lib/ld-linux.so.2 #28 0x01a08209 in exit () from /lib/i686/nosegneg/libc.so.6 #29 0x019f1ea4 in __libc_start_main () from /lib/i686/nosegneg/libc.so.6 #30 0x0804b8a1 in _start ()

it is clear that it’s a problem of deleting the TFile I opened. I tried different solutions, i.e. deleting the file in the descructor but it didn’t help.
How am I supposed to delete the file?

I have never had this problem when doing this in macros.

cheers,
delo

Hi,

I run valgrind and new hints came up related to CleanUpRooFitAtExit()

at 0x41346AA: TObject::~TObject() (in /afs/cern.ch/atlas/software/releases/17.0.4/sw/lcg/app/releases/ROOT/5.28.00g/i686-slc5-gcc43-opt/root/lib/libCore.so) ==2122== by 0x61080DF: RooAbsCollection::~RooAbsCollection() (in /afs/cern.ch/atlas/software/releases/17.0.4/sw/lcg/app/releases/ROOT/5.28.00g/i686-slc5-gcc43-opt/root/lib/libRooFitCore.so) ==2122== by 0x61796E4: RooArgSet::~RooArgSet() (in /afs/cern.ch/atlas/software/releases/17.0.4/sw/lcg/app/releases/ROOT/5.28.00g/i686-slc5-gcc43-opt/root/lib/libRooFitCore.so) ==2122== by 0x627D91F: RooPlot::~RooPlot() (in /afs/cern.ch/atlas/software/releases/17.0.4/sw/lcg/app/releases/ROOT/5.28.00g/i686-slc5-gcc43-opt/root/lib/libRooFitCore.so) ==2122== by 0x419FC2C: TCollection::GarbageCollect(TObject*) (in /afs/cern.ch/atlas/software/releases/17.0.4/sw/lcg/app/releases/ROOT/5.28.00g/i686-slc5-gcc43-opt/root/lib/libCore.so) ==2122== by 0x41A2B86: THashList::Delete(char const*) (in /afs/cern.ch/atlas/software/releases/17.0.4/sw/lcg/app/releases/ROOT/5.28.00g/i686-slc5-gcc43-opt/root/lib/libCore.so) ==2122== by 0x411C04A: TDirectory::~TDirectory() (in /afs/cern.ch/atlas/software/releases/17.0.4/sw/lcg/app/releases/ROOT/5.28.00g/i686-slc5-gcc43-opt/root/lib/libCore.so) ==2122== by 0x4D65D6D: TDirectoryFile::~TDirectoryFile() (in /afs/cern.ch/atlas/software/releases/17.0.4/sw/lcg/app/releases/ROOT/5.28.00g/i686-slc5-gcc43-opt/root/lib/libRIO.so) ==2122== by 0x419FC2C: TCollection::GarbageCollect(TObject*) (in /afs/cern.ch/atlas/software/releases/17.0.4/sw/lcg/app/releases/ROOT/5.28.00g/i686-slc5-gcc43-opt/root/lib/libCore.so) ==2122== by 0x41A2B86: THashList::Delete(char const*) (in /afs/cern.ch/atlas/software/releases/17.0.4/sw/lcg/app/releases/ROOT/5.28.00g/i686-slc5-gcc43-opt/root/lib/libCore.so) ==2122== by 0x4D65362: TDirectoryFile::Close(char const*) (in /afs/cern.ch/atlas/software/releases/17.0.4/sw/lcg/app/releases/ROOT/5.28.00g/i686-slc5-gcc43-opt/root/lib/libRIO.so) ==2122== by 0x4D817D3: TFile::Close(char const*) (in /afs/cern.ch/atlas/software/releases/17.0.4/sw/lcg/app/releases/ROOT/5.28.00g/i686-slc5-gcc43-opt/root/lib/libRIO.so) ==2122== Address 0x10ddfcbc is 4,188 bytes inside a block of size 1,048,576 free'd ==2122== at 0x4006516: free (vg_replace_malloc.c:325) ==2122== by 0x6179BA2: RooArgSet::cleanup() (in /afs/cern.ch/atlas/software/releases/17.0.4/sw/lcg/app/releases/ROOT/5.28.00g/i686-slc5-gcc43-opt/root/lib/libRooFitCore.so) ==2122== by 0x62C614E: CleanUpRooFitAtExit() (in /afs/cern.ch/atlas/software/releases/17.0.4/sw/lcg/app/releases/ROOT/5.28.00g/i686-slc5-gcc43-opt/root/lib/libRooFitCore.so)

it sounds a bit obscure to me but is it possible that when “cleaning up” it also destroy the file I opened?
It seems to be triggered by a ~RooPlot(). Commenting out all the RooPlot objects it dosen’t crash anymore

cheers,
delo

ok I probably solved the problem.
I had to delete all the RooPlot objects I created with

RooPlot *xframe=Mass->frame(nbin);
I was missing one…

cheers,
delo

Hi,

the initial problem re-appered adding or changing some code.
Looking at the initial stack trace I noticed that the problem was related with a TProfile object.
I somehow understood that my TProfiles were descructed by the discructor of my class (~Boosted) but also
when distructing the file from which I was reading some histogram.
Just adding

solved my problem.
I don’t know why I don’t have to do this for all the other objects such as TH1.

cheers,
delo