-
Notifications
You must be signed in to change notification settings - Fork 2k
Fix GeometryGroup.Children.Clear() leaking shared child geometries #36232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kubaflo
merged 4 commits into
dotnet:inflight/current
from
devanathan-vaithiyanathan:fix-35795
Jul 2, 2026
+158
−26
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| using Microsoft.Maui.Controls.Shapes; | ||
| using Rect = Microsoft.Maui.Graphics.Rect; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.Maui.Controls.Core.UnitTests; | ||
|
|
||
| public class GeometryGroupTests : BaseTestFixture | ||
| { | ||
| [Fact] | ||
| public void ClearUnsubscribesPreviousChildrenFromPropertyChanged() | ||
| { | ||
| var group = new GeometryGroup(); | ||
| var oldChild = new RectangleGeometry(new Rect(0, 0, 10, 10)); | ||
| var newChild = new RectangleGeometry(new Rect(0, 0, 5, 5)); | ||
| var invalidations = 0; | ||
|
|
||
| group.InvalidateGeometryRequested += (_, _) => invalidations++; | ||
|
|
||
| group.Children.Add(oldChild); | ||
| invalidations = 0; | ||
|
|
||
| group.Children.Clear(); | ||
| invalidations = 0; | ||
|
|
||
| // If Reset handling does not unsubscribe old items, this mutation incorrectly invalidates the group. | ||
| oldChild.Rect = new Rect(1, 1, 11, 11); | ||
| Assert.Equal(0, invalidations); | ||
|
|
||
| group.Children.Add(newChild); | ||
| invalidations = 0; | ||
|
|
||
| newChild.Rect = new Rect(2, 2, 6, 6); | ||
| Assert.Equal(1, invalidations); | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[moderate] Regression Prevention and Test Coverage — A prior review comment on this PR explicitly asked for "a unit test covering duplicate add/remove" after the fix moved from a
HashSetto a ref-countedDictionary<Geometry,int>specifically to handle the sameGeometryinstance being added toChildrenmore than once. That code change was made inGeometryGroup.cs, but no test for it was added here — the only test covers a single non-duplicate child through aClear()/Reset cycle. Concrete failing scenario the current suite would miss if the ref-counting regressed: add the sameGeometryinstance twice,RemoveAtone occurrence, then mutate the geometry — it should still raiseInvalidateGeometryRequested(subscription is only removed once the ref count reaches 0), and aReplacethat substitutes one duplicate for another already-present instance should also keep the surviving subscription intact. Please add these cases so the ref-counting behavior — and the exact scenario in the linked issue title, "leaking shared child geometries" — is regression-tested, not just the simple Clear() path.