Problem 775 - managers delete user actions in their destructors
Summary: managers delete user actions in their destructors
Status: RESOLVED INVALID
Alias: None
Product: Geant4
Classification: Unclassified
Component: run (show other problems)
Version: 7.1
Hardware: All All
: P2 normal
Assignee: Makoto.Asai
URL:
Depends on:
Blocks:
 
Reported: 2005-07-29 15:15 CEST by jasondet
Modified: 2005-08-04 13:05 CEST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this problem.
Description jasondet 2005-07-29 15:15:04 CEST
I noticed that the managers (e.g. G4RunManager (and G4TrackingAction,
G4SteppingAction, etc)) delete their user actions (e.g. userRunAction) in their
destructors. This seems strange, because the user actions are always allocated
outside of the managers. Without a method to explicitly transfer "ownership" of
a user action pointer, one would expect a region of code that allocates a user
action to retain control over when it is to be deleted. So I recommend that the
managers NOT delete their user actions. If it is preferred that the managers do
gain ownership of their user actions, this should somehow be made explicit
(users should not be expected to just "know" this), and there should be a flag
allowing one to remove ownership if desired. Actually, the same goes for the
detector construction, the physics list, and the primary generator action.

This problem caused a segmentation fault for me when I attempted to make a class
deriving from both G4UserSteppingAction and G4UserRunAction. I allocated a new
instance of this class in my main block, and gave the pointer to the
G4RunManager as both a G4UserSteppingAction* and a G4UserRunAction*. The seg
fault occured when both the G4SteppingManager and the G4RunManager attempted to
delete the same region of memory in their destructors, which I expected to
delete myself in main.
Comment 1 asai 2005-08-04 13:05:59 CEST
It is stated so in the users guide that deleting G4RunManager causes deletion
of all user action classes. Also, I do not see any good reason to make a class
derived from both RunAction and SteppingAction. If you have a class need to be
invoked from both of these action classes, take one of two possible ways.
1) Add a method in your SteppingAction class which can be invoked from your
RunAction class.
2) Create a class to be accessed from both of your RunAction and SteppingAction
classes.
I suggest you to avoid multiple-inheritance.