-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Description
Reviewing some memory dumps and it seems like there's a possible leak with CollectionViewHandler2
maui/src/Controls/src/Core/Handlers/Items2/CollectionViewHandler2.iOS.cs
Lines 202 to 220 in 5fc2590
| void SubscribeToItemsLayoutPropertyChanged(IItemsLayout itemsLayout) | |
| { | |
| if (itemsLayout is not null) | |
| { | |
| itemsLayout.PropertyChanged += (sender, args) => | |
| { | |
| if (args.PropertyName == nameof(ItemsLayout.SnapPointsAlignment) || | |
| args.PropertyName == nameof(ItemsLayout.SnapPointsType) || | |
| args.PropertyName == nameof(GridItemsLayout.VerticalItemSpacing) || | |
| args.PropertyName == nameof(GridItemsLayout.HorizontalItemSpacing) || | |
| args.PropertyName == nameof(GridItemsLayout.Span) || | |
| args.PropertyName == nameof(LinearItemsLayout.ItemSpacing)) | |
| { | |
| UpdateLayout(); | |
| } | |
| }; | |
| } | |
| } |
I'm not sure off hand the most reasonable place to unsubscribe from this.
We could/should do it in disconnecthandler but it'd be nice to do it somewhere else that we always know it'll fire from.
Maybe we can unsubscribe/subscribe to this when the view is attached/removed from the window?
Maybe there's a way to subscribe to it from the level of the CollectionView itself and we have it fire a mapper that triggers the UpdateLayout call?
I'm a little curious why we're subscribing to events on a static variable, that feels like it won't do anything useful.
Workaround
This issue comes from the default ItemsLayout because a static instance which means if you subscribe to it you won't get GC'd
<CollectionView>
<CollectionView.ItemsLayout>
<LinearItemsLayout Orientation="Vertical" />
</CollectionView.ItemsLayout>
</CollectionView>Metadata
Metadata
Assignees
Labels
Type
Projects
Status
