Deletion of GateMultiSensitiveDetector::pMultiFunctionalDetector and the Segfaults
Deleting a G4MultiFunctionalDetector invokes the deletion of the registered primitives. Consequently, the deletion of GateMultiSensitiveDetector::pMultiFunctionalDetector invokes the deletion of Gate actors. There are two scenarios in which GateMultiSensitiveDetector::pMultiFunctionalDetector is deleted:
-
delete pMultiFunctionalDetectoris called inGateMultiSensitiveDetector::~GateMultiSensitiveDetector() -
GateMultiSensitiveDetector::pMultiFunctionalDetectoris registered to theG4SDManagerwhich takes the ownership.
People have been commenting in and out these cases in there commits, e.g. bda725bdccd9ade5d12f343c70464b3de241471f, because they figured it causes segfaults.
The deeper problem is the following: the singleton GateActorManager also claims ownership of all Gate actors, implementing their deletion in GateActorManager::~GateActorManager(). That causes a double free, if GateMultiSensitiveDetector::pMultiFunctionalDetector is deleted, too.
You're right sorry ... What's the solution in your opinion ? Remove the loop that delete all actor in GateActorManager::~GateActorManager() ?
First of all: thanks for the quick reply and thanks for the work you put into Gate.
Yeah, what you suggest is the provisional fix I was thinking of: Allow the deletion of GateMultiSensitiveDetector::pMultiFunctionalDetector and remove the loop in GateActorManager::~GateActorManager().
On the long term, the GateVActor <--> GateActorManager <--> GateMultiSensitiveDetector interfaces might need some more invasive refactoring.
ok, done 12dd4c4f4267d10cda6ee6bed70ac869c903b28e
Maybe, I was too quick with my suggestion... @dsarrut I saw, that you encountered problems again (see 8a23dd500ea70ba226f7dc6d9af04611210b23be), so maybe this issue should be re-opened.
Two important points:
-
At the moment, no actors are deleted, neither by
GateMultiSensitiveDetector::pMultiFunctionalDetectornor by theGateActorManager, right? -
I also noticed, that because some actors don't need to be attached to a volume (e.g. simulation statistics actor), they never become owned by a
GateMultiSensitiveDetector::pMultiFunctionalDetector. Hence, deletingGateMultiSensitiveDetector::pMultiFunctionalDetectorcannot be the general delete mechanism for actors.
In general, though, how do you track down your segfaults to the deletion of GateMultiSensitiveDetector::pMultiFunctionalDetector?
Not clear how the cleaning is currently performed. I should investigate ... Maybe a shared_ptr approach could help, but will require lot of changes. Not time for this right now.
In general, though, how do you track down your segfaults to the deletion of GateMultiSensitiveDetector::pMultiFunctionalDetector? I just look trace with gdb ...