Repository navigation
prune expired callback groups - #3437
Conversation
|
This resolved a current bug in Nav2 we would like backported - we end up running into this because we construct potentially hundreds of behavior trees in a single session due to multiple runs with iteratively changing behaviors. So we end up creating a bunch of new callback groups for particular BT node ROS interfaces, which triggers this issue. Over the course of day(s) of operations it can end up hogging memory. PS to maintainers - the test failures seem unrelated to this change |
ABI Compliance Check✅ Verdict: compatible
✅
|
|
Pulls: #3437 |
|
I think the Rpr build failure is due to ros2/rcl#1358 not being released/bloomed and synced to the testing repo; it's trying to build against an older version of |
christophebedard
left a comment
There was a problem hiding this comment.
LGTM, thanks for the fix.
Could you just amend & sign-off your commit?
|
I slightly changed the PR description so that the referenced issue gets closed when this gets merged. |
|
We had complains with similar patches in the past. What about adding an argument defaulting to true for pruning ? |
|
Good point. What if we only prune when the vector is full, i.e., |
The pattern in this PR is the same as how subscriptions, timers, etc are handled. I think for consistency this is the best solution. I also (personally) don't see a motivating non-theoretical reason for disabling that pruning.
How do we decide how much we set the default capacity to? I imagine that would need to be a parameter to reserve the size on setup. I think my comment above is similar that if we did that for the callback groups, we'd want to do that for the interfaces too for consistency (probably a parameter for each one for the advanced user that wants to specifically state the number to avoid allocations). I think that's more of 'future work' / new ticket ground, since that is a not-super-related feature addition to what we're doing here, which has current codebase prescience. Admittedly my bias is for consistency over most over considerations in how I maintain Nav2 so the same patterns repeat for familiarity. |
|
I'm personally fine with taking this as-is and considering an improvement later. This is an initialization-time thing anyway.
I would've just not set a default capacity and let it double (or whatever) its capacity when it's full |
|
I'll proceed with this as soon as the commit is signed off; we can follow-up with an improvement later. |
Signed-off-by: Joshua Wallace <josho.wallace@gmail.com>
4666471 to
741dddb
Compare
|
the commit was amended without making any code changes, so I'll just merge this. |
|
@jmachowinski @SteveMacenski FYI I opened a follow-up issue based on the discussion above: #3463 |
Description
Weak pointers to the destroyed callback groups were never removed from
NodeBase::callback_groups_. Each expired weak pointer keeps the group's allocation alive. This causes the memory to grow for every callback group added or destroyed.This fix follows the same pattern as
CallbackGroup::add_subscriptionand other add methods.Using the script provided in the ticket I verified that the memory leak no longer exists.
Fixes #3428
Is this user-facing behavior change?
Did you use Generative AI?
I used generative AI to test the fix and find find out how this particular issue was handled for callbacks.
Additional Information