Skip to content

[Simulation.Core] WorkerThread: fix memory leak/resource retention#6125

Open
fredroy wants to merge 2 commits into
sofa-framework:masterfrom
fredroy:update_scheduler_dtor_leak
Open

[Simulation.Core] WorkerThread: fix memory leak/resource retention#6125
fredroy wants to merge 2 commits into
sofa-framework:masterfrom
fredroy:update_scheduler_dtor_leak

Conversation

@fredroy

@fredroy fredroy commented May 27, 2026

Copy link
Copy Markdown
Contributor

In WorkerThread, the task destructor was commented. (???)
As of now, the task is only deallocated in memory but the dtor is not called thus its resources are not freed -> memory leak

For now, I am just adding a test illustrating/proving the bug and then will push the fix later
Done

[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 pr: test PR adding test(s) in SOFA pr: AI-aided Label notifying the reviewers that part or all of the PR has been generated with the help of an AI labels May 27, 2026
@fredroy fredroy force-pushed the update_scheduler_dtor_leak branch 2 times, most recently from ef20bb1 to 69d8a29 Compare May 27, 2026 22:28
@bakpaul bakpaul added pr: status wip Development in the pull-request is still in progress and removed pr: status to review To notify reviewers to review this pull-request labels Jun 4, 2026
@fredroy fredroy force-pushed the update_scheduler_dtor_leak branch from 69d8a29 to 507ffe5 Compare June 7, 2026 23:46
@fredroy fredroy added pr: status to review To notify reviewers to review this pull-request and removed pr: status wip Development in the pull-request is still in progress labels Jun 7, 2026
fredroy added 2 commits June 8, 2026 08:58
- task->~Task() is now called before operator delete. Because ~Task() is virtual (Task.h:56), this
  dispatches to the actual derived destructor  ~CallableTask, ~SharedPtrHoldingTask, etc.
  - Captured sizeof(*task) into a local taskSize before calling the destructor, then passed it to operator
  delete. Reading sizeof(*task) after destruction would technically be reading a destroyed object's vtable,
  which is UB. With the local capture we sidestep that. (sizeof is a compile-time expression on the static
  type of *task, so the value is the same  but using a local makes the intent explicit and avoids
  reasoning-trap.)
@fredroy fredroy force-pushed the update_scheduler_dtor_leak branch from 507ffe5 to e037880 Compare June 8, 2026 00:10
@fredroy

fredroy commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: AI-aided Label notifying the reviewers that part or all of the PR has been generated with the help of an AI pr: fix Fix a bug pr: status to review To notify reviewers to review this pull-request pr: test PR adding test(s) in SOFA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants