fix memory leak for data of UserTrackInfo #462
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes a memory leak with the G4UserTrackInfo in the HostTrackData:
When the track was given to AdePT, the G4UserTrackInfo pointer is set to null to avoid the deletion of the underlying data that AdePT still needs to access. However, that makes AdePT responsible for deleting the underlying data of the G4UserTrackInfo pointer. The deletion was missing and was added: Now, the data is deleted when the track is finished on GPU and the
removeTrackof the HostTrackData is called. If the track is given back to CPU, the ownership of the data is transferred back to G4. In case of Gamma-nuclear, the leakedTrack can be deleted, as the gamma does not survive the process. Then, the underlying data also needs to be deleted, the pointer set to null and then, the track can be safely deleted to avoid double deletion.Additional change: the
removeTrackwas called after thePostUserTrackingActionfor a returned step that was flagged as the last step of a track, however, theSensitiveDetector->Hit()was called after. Thus, theremoveTrackis moved to be called after theSensitiveDetector->Hit()is called.This fixes a memory leak in CMSSW when MC truth is used.