Skip to content

Conversation

@SeverinDiederichs
Copy link
Collaborator

@SeverinDiederichs SeverinDiederichs commented Dec 9, 2025

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 removeTrack of 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 removeTrack was called after the PostUserTrackingAction for a returned step that was flagged as the last step of a track, however, the SensitiveDetector->Hit() was called after. Thus, the removeTrack is moved to be called after the SensitiveDetector->Hit() is called.

This fixes a memory leak in CMSSW when MC truth is used.

@SeverinDiederichs SeverinDiederichs added the bug Type: Something isn't working label Dec 9, 2025
@phsft-bot
Copy link

Can one of the admins verify this patch?

Copy link
Contributor

@JuanGonzalezCaminero JuanGonzalezCaminero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unfortunate that we have to manage the user info in this way, I think the comments explain the steps well, thank you for the change!

@SeverinDiederichs SeverinDiederichs merged commit 56d658b into apt-sim:master Dec 15, 2025
3 checks passed
@SeverinDiederichs SeverinDiederichs deleted the fix_UserTrackInfo_memleak branch December 15, 2025 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Type: Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants