Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

[Android] Dispose the collection view item adapter #6525

Merged
merged 2 commits into from
Jun 20, 2019

Conversation

kvpt
Copy link
Contributor

@kvpt kvpt commented Jun 13, 2019

Description of Change

The adapter was not dispose which was causing a leak with the item source.

Issues Resolved

API Changes

None

Platforms Affected

  • Android

Behavioral/Visual Changes

None

Before/After Screenshots

Not applicable

Testing Procedure

Like all other garbage collection issue, it very difficult to produce a reliable reproduction.
I tried to make a reproduction case from the elements of the issue #6427 without success.

PR Checklist

  • Has automated tests
  • Rebased on top of the target branch at time of PR
  • Changes adhere to coding standard

@kvpt kvpt requested a review from StephaneDelcroix as a code owner June 13, 2019 22:48
@kvpt kvpt changed the base branch from master to 4.1.0 June 13, 2019 22:48
@samhouts samhouts removed the request for review from StephaneDelcroix June 13, 2019 23:02
@samhouts samhouts added a/collectionview i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often t/bug 🐛 p/Android labels Jun 13, 2019
@samhouts samhouts requested review from hartez and samhouts June 13, 2019 23:24
@kvpt
Copy link
Contributor Author

kvpt commented Jun 16, 2019

I made a more correct fix.

I have modified two parts :

  • In UpdateAdapter, Unwatch and Dispose the old adapter, this part was missing.
  • In TearDownOldElement Unwatch and Dispose the adapter ItemsViewAdapter in all case.

The problem in this one was that the adapter was retrieved by the GetAdapter method, so if the adapter was previously swapped with the _emptyViewAdapter the GetAdapter method returned _emptyViewAdapter and not ItemsViewAdapter, so ItemsViewAdapter was never disposed.
_emptyViewAdapter has nothing to dispose so the only adapter we want to dispose is not the current one, it is ItemsViewAdapter.

I also noticed an inconsistency in the naming of the callbacks, don't know if it's too late or not to be changed.

  • LayoutOnPropertyChanged => OnLayoutPropertyChanged
  • ScrollToRequested => OnScrollToRequested

@samhouts samhouts requested a review from hartez June 17, 2019 20:36
@hartez
Copy link
Contributor

hartez commented Jun 19, 2019

nconsistency in the naming of the callbacks, don't know if it's too late or not to be changed.

I we were going to change it, that would need to happen in a different PR. PRs need to be focused.

@samhouts samhouts added the approved Has two approvals, no pending reviews, and no changes requested label Jun 20, 2019
@samhouts samhouts merged commit 22dd496 into xamarin:4.1.0 Jun 20, 2019
@kvpt kvpt deleted the collection_view_dispose_fix branch June 20, 2019 12:12
@samhouts samhouts added this to the 4.1.0 milestone Jun 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/collectionview approved Has two approvals, no pending reviews, and no changes requested i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often p/Android t/bug 🐛
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants