Skip to content

[Core] BaseObject: remove components from the slave list#5891

Merged
hugtalbot merged 2 commits intosofa-framework:masterfrom
fredroy:cleanup_slaves
Feb 6, 2026
Merged

[Core] BaseObject: remove components from the slave list#5891
hugtalbot merged 2 commits intosofa-framework:masterfrom
fredroy:cleanup_slaves

Conversation

@fredroy
Copy link
Contributor

@fredroy fredroy commented Jan 27, 2026

Related (and fix) : #5890

Description:
Searching for memory leaks, I detected big ones coming from TetrahedronFEMForcefield.
In particular the colorMap, which was supposed to be deleted in the destructor.
I noticed that the destructor was not called and then... asked Claude which found that slaves was keeping a reference to their owner, and so the reference counter of the Sptr was not at the end of the program (so not the dtor was not called).

Easy solution is to unlink the slaves during the cleanup phase (what is done in this PR)
Only problem is if a component is overriding this function and not calling super::cleanup() 💀
(template method design blabla for BaseObject blabla 🫠)

[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

  • it builds with SUCCESS for all platforms on the CI.
  • it does not generate new warnings.
  • it does not generate new unit test failures.
  • it does not generate new scene test failures.
  • it does not break API compatibility.
  • it is more than 1 week old (or has fast-merge label).

@fredroy fredroy added pr: fix Fix a bug pr: status to review To notify reviewers to review this pull-request labels Jan 27, 2026
@hugtalbot hugtalbot added the topic for next dev-meeting PR to be discussed in sofa-dev meeting label Jan 27, 2026
@fredroy
Copy link
Contributor Author

fredroy commented Jan 27, 2026

[ci-build][with-all-tests]

@alxbilger
Copy link
Contributor

I still cannot make up my mind if the responsibility to clean up slaves is on the base or derived class...

@bakpaul
Copy link
Contributor

bakpaul commented Feb 4, 2026

It depends what does the remove do when called. Does the slave run a callback that might act on the owner ? Is there any way this callback could access the owner ? If this is the case, IMO the safest way to go would be to make the most derived class to do this. But in the meantime if it is the case, I guess there is a design flaw.

So for me the best way to go is to make sure no such callback exists and the slaves never access their owner in the destructor and keep this in the BaseObject destructor

@hugtalbot hugtalbot added pr: status ready Approved a pull-request, ready to be squashed and removed pr: status to review To notify reviewers to review this pull-request topic for next dev-meeting PR to be discussed in sofa-dev meeting labels Feb 5, 2026
@hugtalbot hugtalbot merged commit fbcd5e5 into sofa-framework:master Feb 6, 2026
9 of 13 checks passed
@hugtalbot hugtalbot deleted the cleanup_slaves branch February 6, 2026 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: fix Fix a bug pr: status ready Approved a pull-request, ready to be squashed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants