Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Ensure disconnected ItemsViewHandler doesn't hold onto the items source #24610

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

filipnavara
Copy link
Member

Description of Change

Any control derived from ItemsView (CarouselView, CollectionView) never disconnected from the ItemsSource.CollectionChanged callback when DisconnectHandler() is called. If the lifetime of the item source outlives the controls it can result in the CollectionChanged callback keeping part of the UI tree alive in a half-zombie state. Any change then calls the callback and it may cause crashes with NullReferenceException as seen in #24304.

Issues Fixed

Fixes #24304

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Sep 5, 2024
Copy link
Contributor

Hey there @filipnavara! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@PureWeen
Copy link
Member

PureWeen commented Sep 5, 2024

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen
Copy link
Member

PureWeen commented Sep 5, 2024

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@filipnavara filipnavara marked this pull request as ready for review September 6, 2024 06:45
@filipnavara filipnavara requested a review from a team as a code owner September 6, 2024 06:45
@PureWeen
Copy link
Member

PureWeen commented Sep 6, 2024

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen PureWeen requested review from jonathanpeppers and removed request for tj-devel709 September 6, 2024 17:08
jonathanpeppers
jonathanpeppers previously approved these changes Sep 6, 2024
Copy link
Member

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@filipnavara
Copy link
Member Author

Looks like Unit tests are failing

Apparently MarshalingObservableCollection tests depend on the collection changing without ever registering for the CollectionChanged event. That makes it tricky to implement the behavior on Android correctly since there's no explicit disposal of the MarshalingObservableCollection that is internally created by the ItemsSourceFactory.

@PureWeen
Copy link
Member

Looks like Unit tests are failing

Apparently MarshalingObservableCollection tests depend on the collection changing without ever registering for the CollectionChanged event. That makes it tricky to implement the behavior on Android correctly since there's no explicit disposal of the MarshalingObservableCollection that is internally created by the ItemsSourceFactory.

Hmmm, maybe for now we just restore MarshalingObservableCollection so it subscribes in the ctor and make sure that calling disconnecthandler on Android will correctly unsubscribe. I realize that's not currently ideal but that would at least let us merge this PR and fix the crasher on iOS

@filipnavara
Copy link
Member Author

Hmmm, maybe for now we just restore MarshalingObservableCollection so it subscribes in the ctor and make sure that calling disconnecthandler on Android will correctly unsubscribe.

Would it be okay to add implementation of IDisposable interface to MarshalingObservableCollection?

@rmarinho
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@filipnavara
Copy link
Member Author

filipnavara commented Sep 10, 2024

The test failure looks relevant. I don't see why it happens though, and I will need to reproduce it locally.

Copy link
Member

@rmarinho rmarinho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @filipnavara since #24699 was merged, can we rebase this for the other platforms?

@filipnavara
Copy link
Member Author

Sure. I am away until next week but I will revive the PR when I get back home.

@filipnavara filipnavara changed the title [iOS] Ensure disconnected ItemsViewHandler doesn't hold onto the items source [Android] Ensure disconnected ItemsViewHandler doesn't hold onto the items source Oct 18, 2024
@jsuarezruiz
Copy link
Contributor

/rebase

@PureWeen PureWeen added this to the .NET 9 SR1 milestone Oct 23, 2024
@rmarinho rmarinho self-assigned this Oct 31, 2024
@PureWeen PureWeen modified the milestones: .NET 9 SR1, .NET 9 Servicing Nov 6, 2024
@rmarinho
Copy link
Member

/azp run

@dotnet dotnet deleted a comment from azure-pipelines bot Nov 27, 2024
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@dotnet dotnet deleted a comment from jsuarezruiz Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView community ✨ Community Contribution platform/iOS 🍎
Projects
Status: Ready To Review
Development

Successfully merging this pull request may close these issues.

Crash on NullReferenceException with measurement cells in CollectionView
6 participants