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

Fixed the memory leak in the collectionview and gallery #14076

Merged

Conversation

jtorvald
Copy link
Contributor

Description of Change

Event handlers on the TemplatedCell are not being removed which results in the control to be left in memory which keeps the page where it is loaded also to stay behind in memory.

I added an unbind method on the TemplatedCell and unbind the event handlers in the ItemsViewController.
Also the TemplatedItemsList had a collectionchanged event which was not removed so I removed that as well.

If there is a better way to achieve this, please let me know and I will fix it in a better way.

Xamarin.Forms.Core/TemplatedItemsList.cs
Xamarin.Forms.Platform.iOS/CollectionView/ItemsViewController.cs
Xamarin.Forms.Platform.iOS/CollectionView/TemplatedCell.cs

All the other files are eventhandler fixes in the Gallery code.

Issues Resolved

API Changes

Added: Unbind() on TemplatedCell.cs to remove events

Platforms Affected

  • iOS
  • Android

Behavioral/Visual Changes

None

Before/After Screenshots

Not applicable

Testing Procedure

Go to the templated collectionview pages in the gallery and go back. Repeat couple of times and see page count increasing in the Xamarin Profiler.

PR Checklist

  • Targets the correct branch
  • Tests are passing (or failures are unrelated)

@jtorvald
Copy link
Contributor Author

I tried to reach out to different community members get some confirmation on this issue and a review since it's my first PR here. Since everybody seems to be busy with Maui ;-) I just sent this PR to the 5.0.0 branch so it will not be forgotten.

@jsuarezruiz jsuarezruiz added a/collectionview a/performance i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often labels Apr 28, 2021
@jsuarezruiz jsuarezruiz added this to Issues in Progress in 5.0.0 SR6 (Planning) - Target Date Oct. 13th via automation Sep 16, 2021
@jsuarezruiz jsuarezruiz self-requested a review September 16, 2021 11:47
@jsuarezruiz jsuarezruiz merged commit 64c972d into xamarin:5.0.0 Sep 21, 2021
5.0.0 SR6 (Planning) - Target Date Oct. 13th automation moved this from Issues in Progress to Done Sep 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/collectionview a/performance i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often p/iOS 🍎
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

[Bug] Collection view has memory leak in iOS
2 participants