diff --git a/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.iOS.cs b/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.iOS.cs index c67911fb667c..846728b101da 100644 --- a/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.iOS.cs +++ b/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.iOS.cs @@ -17,7 +17,7 @@ public abstract partial class ItemsViewHandler : ViewHandler await AssertionExtensions.WaitForGC(viewReference, handlerReference, platformViewReference); } + [Fact("CollectionView Header/Footer Doesn't Leak")] + public async Task CollectionViewHeaderFooterDoesntLeak() + { + SetupBuilder(); + + WeakReference viewReference = null; + WeakReference handlerReference = null; + WeakReference controllerReference = null; + + var observable = new ObservableCollection { 1 }; + var navPage = new NavigationPage(new ContentPage { Title = "Page 1" }); + + await CreateHandlerAndAddToWindow(new Window(navPage), async () => + { + var cv = new CollectionView + { + Footer = new VerticalStackLayout(), + Header = new VerticalStackLayout(), + ItemTemplate = new DataTemplate(() => + { + var view = new Label + { + }; + view.SetBinding(Label.TextProperty, "."); + return view; + }), + ItemsSource = observable + }; + + viewReference = new WeakReference(cv); + handlerReference = new WeakReference(cv.Handler); + + + await navPage.Navigation.PushAsync(new ContentPage + { + Content = cv + }); + + + #if IOS + var controller = (cv.Handler as CollectionViewHandler).Controller; + controllerReference = new WeakReference(controller); + controller = null; + #else + controllerReference = new WeakReference(new object()); + #endif + + cv = null; + + await navPage.Navigation.PopAsync(); + }); + + await AssertionExtensions.WaitForGC(viewReference, handlerReference, controllerReference); + } + [Theory("Gesture Does Not Leak")] [InlineData(typeof(DragGestureRecognizer))] [InlineData(typeof(DropGestureRecognizer))]