Skip to content

[CV][Android] fails to disconnect handlers when items are removed or DataTemplateSelector switches templates #32243

Description

@Vetle444

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

  1. Create a CollectionView with a DataTemplateSelector that switches between two templates based on item state
  2. Initially render some items with Template A
  3. Change the item state so all items now use Template B (Template A is no longer used)
  4. Observe that handlers for controls in Template A instances remain connected

Scenario 2: Removing items from CollectionView

  1. Create a CollectionView with items
  2. Remove items from the ObservableCollection (using RemoveAt(), Remove(), or Clear())
  3. 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.

Image

Steps to Reproduce

  1. Clone https://github.com/Vetle444/MauiTestApp/tree/collectionViewItemHandler
  2. Make sure to be on branch collectionViewItemHandler
  3. Build and deploy app
  4. Navigate to CollectionView Template Handler Test
  5. Click "Switch to all Template B"
  6. Navigate back
  7. Click Show Labels With Connected Handlers
  8. 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

Activity

  1. added
    t/bug
    on Oct 28, 2025
  2. added
    area-controls-collectionview
    on Oct 28, 2025
  3. added this to the .NET 10 SR1 milestone on Oct 28, 2025
  4. TamilarasanSF4853 commented on Oct 28, 2025

    @TamilarasanSF4853
    Contributor

    This issue has been validated in Visual Studio Code 1.105.1 with MAUI versions 9.0.0, 9.0.110 and 9.0.120. It can be reproduced on Android platform.

  5. added
    s/verified
    s/triaged
    on Oct 28, 2025
  6. added
    partner/syncfusion
    on Nov 5, 2025
  7. removed
    partner/syncfusion
    on Dec 4, 2025
  8. added
    partner/syncfusion
    on Mar 18, 2026
  9. 6 remaining items

  10. added this to the .NET 10 SR6 milestone on Apr 29, 2026
  11. locked and limited conversation to collaborators on May 30, 2026
  12. sheiksyedm commented on Jul 7, 2026

    @sheiksyedm
    Contributor

    This issue fix reverted due to regressions. Therefore, reopen this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-controls-collectionviewpartner/syncfusionplatform/androids/triageds/verifiedt/bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions