Skip to content

Conversation

@Tamilarasan-Paranthaman
Copy link
Member

@Tamilarasan-Paranthaman Tamilarasan-Paranthaman commented May 7, 2025

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description of Change

  • The MessagingCenter has been removed from the RadioButtonGroup implementation, and a more direct approach to managing state updates between RadioButton components has been introduced. In this new approach, sibling RadioButton components are accessed directly from their parent hierarchy, allowing the group to update their states and group values without relying on message-based communication. This method mirrors the approach used in non-grouping scenarios, where individual button states are managed and updated by retrieving the buttons from the parent. In the grouping scenario, the same approach is applied, but with the buttons accessed from the VisualRoot, enabling the updating of all related group buttons.
  • Additionally, a ConditionalWeakTable is now used to store and manage the corresponding controller for each RadioButton. This allows for efficient retrieval of the associated controller, enabling the component to update its values and state accordingly when changes occur. By eliminating the overhead introduced by the previous MessagingCenter-based system

Issues Fixed

Fixes #24264

Tested the behaviour in the following platforms

  • Windows
  • iOS
  • Android
  • Mac

Screenshot

Use Case Demo
Same Group on different parent
Same-Group-Diff-Parent.mov
Different Groups
Different-Groups.mov

@dotnet-policy-service dotnet-policy-service bot added community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration labels May 7, 2025
@jfversluis jfversluis added this to the .NET 10.0-preview5 milestone May 12, 2025
@Tamilarasan-Paranthaman Tamilarasan-Paranthaman marked this pull request as ready for review May 15, 2025 15:00
Copilot AI review requested due to automatic review settings May 15, 2025 15:00
@Tamilarasan-Paranthaman Tamilarasan-Paranthaman requested a review from a team as a code owner May 15, 2025 15:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR removes the MessagingCenter-based implementation from the RadioButtonGroup and replaces it with a direct approach using parent hierarchy traversal and a ConditionalWeakTable for efficient controller management. Key changes include:

  • Removing the obsolete MessagingCenter classes and related message constants.
  • Refactoring the RadioButtonGroupController to manage state updates directly and clean up controller associations on child removal.
  • Updating RadioButton and RadioButtonGroup logic to call the new controller methods.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Controls/tests/Core.UnitTests/RadioButtonTests.cs Added a grid layout to group radio buttons in tests.
src/Controls/src/Core/RadioButton/RadioButtonGroupSelectionChanged.cs Removed obsolete MessagingCenter message classes.
src/Controls/src/Core/RadioButton/RadioButtonGroupController.cs Refactored to use ConditionalWeakTable and direct event handling for state updates.
src/Controls/src/Core/RadioButton/RadioButtonGroup.cs Updated grouping logic to uncheck buttons via direct hierarchy traversal.
src/Controls/src/Core/RadioButton/RadioButton.cs Modified property change handlers to use the new controller methods.
Comments suppressed due to low confidence (1)

src/Controls/src/Core/RadioButton/RadioButtonGroupController.cs:89

  • [nitpick] The variable name 'radioButton1' could be more descriptive. Consider renaming it to something like 'childRadioButton' for clarity.
if (element is RadioButton radioButton1)


_layout = (Element)layout;
_layout.ChildAdded += ChildAdded;
_layout.ChildRemoved += ChildRemoved;
Copy link

Copilot AI May 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding an unsubscribe mechanism or disposing pattern for the ChildRemoved (and ChildAdded) event handlers to prevent potential memory leaks when the controller is no longer needed.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tamilarasan-Paranthaman should we indeed also add a -= somewhere?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems the ChildAdded was also not unsubscribe.

Should use the DisconnectHandler to remove these events?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we implement IDisposable to unhook these events? Although there doesn’t seem to be any noticeable leak caused by this.

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@jfversluis jfversluis self-assigned this May 16, 2025
@jfversluis jfversluis added the p/0 Current heighest priority issues that we are targeting for a release. label May 16, 2025
{
internal class RadioButtonGroupController
{
static readonly ConditionalWeakTable<RadioButton, RadioButtonGroupController> groupControllers = new();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there a couple tests, that check this works as we'd expect?

The cases would be:

  • I setup a group of RadioButton on screen in a group, several GCs occur, are they still in the group?
  • I remove a group of RadioButtons from the screen, they go away and do not leak

It reminds me of tests like:

The main goal here was to implement something that doesn't leak, so I think we should also add tests for these cases. Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonathanpeppers, Okay, thanks for sharing the reference. I have checked it along with other memory leak related cases, and based on that, I have added some test cases to the UI, Unit, and Device tests. Could you please take a look and let me know if you have any concerns?

@jonathanpeppers
Copy link
Member

/azp run

Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If CI ends up green, this looks good to me. The new tests are good. 👍

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@dotnet dotnet deleted a comment from azure-pipelines bot May 27, 2025
@rmarinho
Copy link
Member

/rebase

@rmarinho rmarinho removed this from the .NET 10.0-preview5 milestone May 29, 2025
@rmarinho rmarinho added this to the .NET 10.0-preview6 milestone May 29, 2025
@dotnet dotnet deleted a comment from azure-pipelines bot May 29, 2025
@rmarinho rmarinho merged commit 6a96e92 into dotnet:net10.0 May 30, 2025
129 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jun 30, 2025
@Tamilarasan-Paranthaman Tamilarasan-Paranthaman deleted the fix-28855 branch September 24, 2025 09:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-controls-radiobutton RadioButton, RadioButtonGroup community ✨ Community Contribution p/0 Current heighest priority issues that we are targeting for a release. partner/syncfusion Issues / PR's with Syncfusion collaboration platform/android platform/ios platform/macos macOS / Mac Catalyst platform/windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants