diff --git a/src/Controls/src/Core/Compatibility/Handlers/iOS/FrameRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/iOS/FrameRenderer.cs
index 3ecd1611a487..5f16c61d2d14 100644
--- a/src/Controls/src/Core/Compatibility/Handlers/iOS/FrameRenderer.cs
+++ b/src/Controls/src/Core/Compatibility/Handlers/iOS/FrameRenderer.cs
@@ -51,9 +51,7 @@ protected override void OnElementChanged(ElementChangedEventArgs e)
if (e.NewElement != null)
{
- _actualView.CrossPlatformArrange = (e.NewElement as IContentView).CrossPlatformArrange;
- _actualView.CrossPlatformMeasure = (e.NewElement as IContentView).CrossPlatformMeasure;
-
+ _actualView.View = e.NewElement;
SetupLayer();
UpdateShadow();
}
diff --git a/src/Controls/tests/DeviceTests/Elements/ContentView/ContentViewTests.cs b/src/Controls/tests/DeviceTests/Elements/ContentView/ContentViewTests.cs
index 258939f5580b..e963b2095315 100644
--- a/src/Controls/tests/DeviceTests/Elements/ContentView/ContentViewTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/ContentView/ContentViewTests.cs
@@ -76,5 +76,42 @@ await InvokeOnMainThreadAsync(() =>
Assert.True(child.BindingContext == bindingContext);
});
}
+
+ [Fact(DisplayName = "ContentView Does Not Leak")]
+ public async Task DoesNotLeak()
+ {
+ SetupBuilder();
+ WeakReference viewReference = null;
+ WeakReference handlerReference = null;
+ WeakReference platformReference = null;
+
+ {
+ var view = new Microsoft.Maui.Controls.ContentView();
+ var page = new ContentPage { Content = view };
+ await CreateHandlerAndAddToWindow(page, () =>
+ {
+ viewReference = new(view);
+ handlerReference = new(view.Handler);
+ platformReference = new(view.Handler.PlatformView);
+ page.Content = null;
+ });
+ }
+
+ Assert.NotNull(viewReference);
+ Assert.NotNull(platformReference);
+ Assert.NotNull(handlerReference);
+
+ // Multiple GCs are sometimes required on iOS
+ for (int i = 0; i < 3; i++)
+ {
+ await Task.Yield();
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+ }
+
+ Assert.False(viewReference.IsAlive, "View should not be alive!");
+ Assert.False(handlerReference.IsAlive, "Handler should not be alive!");
+ Assert.False(platformReference.IsAlive, "PlatformView should not be alive!");
+ }
}
}
diff --git a/src/Controls/tests/DeviceTests/Elements/NavigationPage/NavigationPageTests.cs b/src/Controls/tests/DeviceTests/Elements/NavigationPage/NavigationPageTests.cs
index 81849abee6b9..2cb7a8bc0808 100644
--- a/src/Controls/tests/DeviceTests/Elements/NavigationPage/NavigationPageTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/NavigationPage/NavigationPageTests.cs
@@ -36,6 +36,7 @@ void SetupBuilder()
handlers.AddHandler();
handlers.AddHandler