fix(winrtble): release radio state handlers on final adapter drop - #477
Merged
Merged
Conversation
Keep radio event registration ownership shared across adapter clones. Use a weak manager reference in the callback and unregister when the last adapter drops. Add Windows hardware regression tests for handler release, adapter clones, and scan cleanup.
Contributor
|
Fix looks good, thanks! |
qdot
self-requested a review
September 20, 2026 19:21
qdot
approved these changes
Sep 20, 2026
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.
Summary
This is the proposed fix for the Windows memory growth described in #476.
Astra wrote this patch and analyzed the memory dumps. I can confirm the difference in memory consumption in my tests, but I can't vouch for the implementation or whether this is the right fix.
Changes
The patch saves the
Radio::StateChangedregistration token and removes the handler when the last adapter clone is dropped. The callback holds a weak reference to the device manager instead of keeping it alive.It leaves the scan-handler cleanup in btleplug 0.13.1 unchanged.
Testing
I ran my application with unpatched 0.13.1 for about eight hours, then with this patch for two hours, using the same five Bluetooth LE devices.
All five devices connected in both runs, with no connection failures logged during measurement. I haven't tested the patched build for eight hours.
Astra's analysis of the matching dumps found radio callbacks increasing from 18 to 3,198 in the unpatched run. With the patch, it found one at both the start and end.
The patch also adds three Windows Bluetooth regression tests covering handler removal, adapter clones, and cleanup after scanning. All three passed, along with the 42 existing library tests. Formatting and library lint checks passed.