[Sofa.Simulation.Core] MappingGraph: fix memory leak in from parent/child shared_ptr cycle - #6259
Open
fredroy wants to merge 1 commit into
Open
[Sofa.Simulation.Core] MappingGraph: fix memory leak in from parent/child shared_ptr cycle#6259fredroy wants to merge 1 commit into
fredroy wants to merge 1 commit into
Conversation
Contributor
Author
|
for windows |
alxbilger
reviewed
Aug 25, 2026
alxbilger
left a comment
Contributor
There was a problem hiding this comment.
Should the children be weak pointers too ? They are supposed to be in m_allNodes too.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
From Claude (sonnet 😅):
BaseMappingGraphNodestored bothm_parentsandm_childrenas owningshared_ptrs.MappingGraph::addEdge()linked every connected pair in both directions, creating a reference cycle between each parent and child node.MappingGraph::clear()(called at the start of everybuild()) only drops the graph's ownm_allNodesvector; it never breaks these cycles. SinceEulerExplicitSolver::solve()andEulerImplicitSolver::solve()callm_mappingGraph.build()unconditionally on every timestep, the entire previous graph leaked on every single animation step for as long as the solver was active.Fix: store
m_parentsasstd::weak_ptrinstead ofshared_ptr. Node ownership already belongs toMappingGraph::m_allNodes(and to each node's owning parent viam_children), so the back-reference doesn't need to be owning.Basically the shared_ptr retained a ref so the parents/childs were owning each other, so the shared_ptr/gc mechanism were effectively dismissed.
Fix #6230
[with-all-tests]
By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).
Reviewers will merge this pull-request only if