Skip to content
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

[ios] fix memory leak in RadioButton #21151

Merged
merged 3 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Controls/src/Core/Border/Border.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void NotifyStrokeShapeChanges()

PureWeen marked this conversation as resolved.
Show resolved Hide resolved
if (strokeShape is VisualElement visualElement)
{
AddLogicalChild(visualElement);
SetInheritedBindingContext(visualElement, BindingContext);
Copy link
Member Author

Choose a reason for hiding this comment

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

@PureWeen maybe you remember if there is something this change would break? This makes Border.StrokeShape and Border.Stroke the same now.

Copy link
Member

@PureWeen PureWeen Mar 14, 2024

Choose a reason for hiding this comment

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

This should be fine

Prior to converting this to AddLogicalChild we were already setting the parent
https://github.com/dotnet/maui/blame/cd7a0e021d99be3ef8c7d83437fb66f5080cd5af/src/Controls/src/Core/Border/Border.cs#L67-L68

Which is why I converted it over to AddLogicalChild during that big push

Stephanes changes with these changes should make this all work alright.

The only weird thing here is if the strokes are static resources this code is still weird, but it's already weird and this makes it less weird at least.

Copy link
Member

Choose a reason for hiding this comment

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

do we need to copy the concept with parent resource propagation that's part of stroke?

OnParentResourcesChanged(this.GetMergedResources());
((IElementDefinition)this).AddResourcesChangedListener(stroke.OnParentResourcesChanged);

Copy link
Member Author

Choose a reason for hiding this comment

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

For Stroke, I guess you could have a GradientBrush that uses a {StaticResource} for a color inside. That seems like it would be required.

For StrokeShape, I guess you can do the exact thing for something like a double value on some shape, so I'll make the properties the same.

_strokeShapeChanged ??= (sender, e) => OnPropertyChanged(nameof(StrokeShape));
_strokeShapeProxy ??= new();
_strokeShapeProxy.Subscribe(visualElement, _strokeShapeChanged);
Expand All @@ -77,7 +77,7 @@ void StopNotifyingStrokeShapeChanges()

if (strokeShape is VisualElement visualElement)
{
RemoveLogicalChild(visualElement);
SetInheritedBindingContext(visualElement, null);
_strokeShapeProxy?.Unsubscribe();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
using System.Text;
using System.Threading.Tasks;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Handlers;
using Microsoft.Maui.Controls.Handlers.Compatibility;
using Microsoft.Maui.Controls.Handlers.Items;
using Microsoft.Maui.Controls.Shapes;
using Microsoft.Maui.DeviceTests.Stubs;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Hosting;
Expand Down Expand Up @@ -33,15 +35,19 @@ void SetupBuilder()
handlers.AddHandler(typeof(TabbedPage), typeof(TabbedViewHandler));
#endif
handlers.AddHandler(typeof(FlyoutPage), typeof(FlyoutViewHandler));
handlers.AddHandler<Page, PageHandler>();
handlers.AddHandler<Window, WindowHandlerStub>();
handlers.AddHandler<Frame, FrameRenderer>();
handlers.AddHandler<Label, LabelHandler>();
handlers.AddHandler(typeof(ScrollView), typeof(ScrollViewHandler));
handlers.AddHandler<Border, BorderHandler>();
handlers.AddHandler<Button, ButtonHandler>();
handlers.AddHandler<CarouselView, CarouselViewHandler>();
handlers.AddHandler<CollectionView, CollectionViewHandler>();
handlers.AddHandler(typeof(Controls.ContentView), typeof(ContentViewHandler));
handlers.AddHandler(typeof(ScrollView), typeof(ScrollViewHandler));
handlers.AddHandler<Frame, FrameRenderer>();
handlers.AddHandler<IContentView, ContentViewHandler>();
handlers.AddHandler<Label, LabelHandler>();
handlers.AddHandler<Layout, LayoutHandler>();
handlers.AddHandler<Page, PageHandler>();
handlers.AddHandler<RadioButton, RadioButtonHandler>();
handlers.AddHandler<Shape, ShapeViewHandler>();
handlers.AddHandler<Window, WindowHandlerStub>();
});
});
}
Expand Down Expand Up @@ -323,6 +329,7 @@ public async Task DoesNotLeak()
new ContentView(),
new Label(),
new ScrollView(),
new RadioButton(),
}
};
pageReference = new WeakReference(page);
Expand Down