Problem 2094 - Static instance of G4StateManager is not cleared on destroy.
Summary: Static instance of G4StateManager is not cleared on destroy.
Status: RESOLVED FIXED
Alias: None
Product: Geant4
Classification: Unclassified
Component: run (show other problems)
Version: 10.4
Hardware: All All
: P4 normal
Assignee: asai
URL:
Depends on:
Blocks:
 
Reported: 2018-10-08 17:07 CEST by andrey.nakin
Modified: 2018-10-12 11:17 CEST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this problem.
Description andrey.nakin 2018-10-08 17:07:16 CEST
The singleton instance of G4StateManager is created in G4StateManager::GetStateManager(). When G4RunManager is stopping, this instance is deleted by G4RunManagerKernel::~G4RunManagerKernel(). But then static variable G4StateManager::theStateManager is not cleared.

The error occurs when the same executable attempts to create 2 or more instances of G4RunManager, see an example here: http://hypernews.slac.stanford.edu/HyperNews/geant4/get/runmanage/440.html
Comment 1 andrey.nakin 2018-10-08 17:37:40 CEST
Suggested fix:

File: G4StateManager.cc
Method: G4StateManager::~G4StateManager()

G4StateManager::~G4StateManager()
{
  G4VStateDependent* state=0;

  while (theDependentsList.size()>0)
  {
    state = theDependentsList.back();
    theDependentsList.pop_back();
    for (std::vector<G4VStateDependent*>::iterator
         i=theDependentsList.begin(); i!=theDependentsList.end();)
    {
      if (*i==state)
      {
        i = theDependentsList.erase(i);
      }
      else
      {
        ++i;
      }
    } 
    if ( state )  { delete state; }
  } 

  theStateManager = 0;  // <-- this is the patch

#ifdef G4MULTITHREADED_DEACTIVATE
  G4iosFinalization();
#endif
}
Comment 2 Gabriele Cosmo 2018-10-12 11:17:00 CEST
Thanks. This is now fixed in the development version and will be available in the next release.