diff --git a/core/base/src/TROOT.cxx b/core/base/src/TROOT.cxx index ba74633d01dd73..9f5c95ea8e841f 100644 --- a/core/base/src/TROOT.cxx +++ b/core/base/src/TROOT.cxx @@ -1129,11 +1129,12 @@ namespace { void TROOT::CloseFiles() { + // Close files without deleting the objects (ResetGlobals will be called next) if (fFiles && fFiles->First()) { R__ListSlowClose(static_cast(fFiles)); } // and Close TROOT itself. - Close("slow"); + Close("nodelete"); // Now sockets. if (fSockets && fSockets->First()) { if (nullptr==fCleanups->FindObject(fSockets) ) { @@ -1212,14 +1213,17 @@ void TROOT::EndOfProcessCleanups() CloseFiles(); if (gInterpreter) { + // This might delete some of the object 'held' by the TFiles (hence + // `CloseFiles` must not delete them) gInterpreter->ResetGlobals(); } - // Now delete the objects 'held' by the TFiles so that it + // Now delete the objects still 'held' by the TFiles so that it // is done before the tear down of the libraries. if (fClosedObjects && fClosedObjects->First()) { R__ListSlowDeleteContent(static_cast(fClosedObjects)); } + fList->Delete("slow"); // Now a set of simpler things to delete. See the same ordering in // TROOT::~TROOT