Description
When items are removed from a CollectionView, or when a DataTemplateSelector switches templates (making certain item templates no longer active), the handlers for controls within those templates are not properly disconnected. This results in memory leaks as the controls and their handlers remain in memory.
Scenario 1: DataTemplateSelector switching templates
- Create a
CollectionView with a DataTemplateSelector that switches between two templates based on item state
- Initially render some items with Template A
- Change the item state so all items now use Template B (Template A is no longer used)
- Observe that handlers for controls in Template A instances remain connected
Scenario 2: Removing items from CollectionView
- Create a
CollectionView with items
- Remove items from the
ObservableCollection (using RemoveAt(), Remove(), or Clear())
- Observe that handlers for controls in the removed items remain connected
Expected Behavior
When a CollectionView item is removed or its template is no longer used, all handlers for controls within that item's template should be automatically disconnected via OnHandlerChanged() being called with a null handler.
Actual Behavior
Handlers remain connected indefinitely. The controls remain in memory and cannot be garbage collected, leading to memory leaks. Only recently created items have their handlers disconnected; older items keep their handlers connected.

Steps to Reproduce
- Clone https://github.com/Vetle444/MauiTestApp/tree/collectionViewItemHandler
- Make sure to be on branch collectionViewItemHandler
- Build and deploy app
- Navigate to
CollectionView Template Handler Test
- Click "Switch to all Template B"
- Navigate back
- Click
Show Labels With Connected Handlers
- Observe that the items that were removed did not have their handler disconnected
Link to public reproduction project repository
https://github.com/Vetle444/MauiTestApp/tree/collectionViewItemHandler
Version with bug
9.0.110 SR12
Is this a regression from previous behavior?
Yes, this used to work in Xamarin.Forms
Last version that worked well
No response
Affected platforms
Android
Affected platform versions
No response
Did you find any workaround?
Some way to disconnect it manually
Relevant log output
Description
When items are removed from a
CollectionView, or when aDataTemplateSelectorswitches templates (making certain item templates no longer active), the handlers for controls within those templates are not properly disconnected. This results in memory leaks as the controls and their handlers remain in memory.Scenario 1: DataTemplateSelector switching templates
CollectionViewwith aDataTemplateSelectorthat switches between two templates based on item stateScenario 2: Removing items from CollectionView
CollectionViewwith itemsObservableCollection(usingRemoveAt(),Remove(), orClear())Expected Behavior
When a CollectionView item is removed or its template is no longer used, all handlers for controls within that item's template should be automatically disconnected via
OnHandlerChanged()being called with a null handler.Actual Behavior
Handlers remain connected indefinitely. The controls remain in memory and cannot be garbage collected, leading to memory leaks. Only recently created items have their handlers disconnected; older items keep their handlers connected.
Steps to Reproduce
CollectionView Template Handler TestShow Labels With Connected HandlersLink to public reproduction project repository
https://github.com/Vetle444/MauiTestApp/tree/collectionViewItemHandler
Version with bug
9.0.110 SR12
Is this a regression from previous behavior?
Yes, this used to work in Xamarin.Forms
Last version that worked well
No response
Affected platforms
Android
Affected platform versions
No response
Did you find any workaround?
Some way to disconnect it manually
Relevant log output