-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[net7.0] [windows] fix memory leak when CollectionView.ItemsSource
changes
#13648
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Fixes: #13393 Context: https://github.com/ivan-todorov-progress/maui-collection-view-memory-leak-bug Debugging the above sample, I found that `ItemsView._logicalChildren` grew indefinitely in size if you replace a `CollectionView`'s `ItemsSource` over and over. I could fix this by creating a new `internal` `ItemsView.ClearLogicalChildren()` method and call it from the Windows `ItemsViewHandler`. I could reproduce this issue in a Device Test running on Windows. It appears the problem does not occur on Android or iOS due to the recycling behavior of the underlying platforms. For example, Android calls `OnViewRecycled()` which calls `RemoveLogicalChild(view)`: * https://github.com/dotnet/maui/blob/53f6e393750a3df05b12fcde442daf3616c216f8/src/Controls/src/Core/Handlers/Items/Android/Adapters/ItemsViewAdapter.cs#L52-L57 * https://github.com/dotnet/maui/blob/53f6e393750a3df05b12fcde442daf3616c216f8/src/Controls/src/Core/Handlers/Items/Android/TemplatedItemViewHolder.cs#L37-L45 On Windows, we merely have a `ItemContentControl` and there is no callback for when things are recycled. We *do* get a callback for when the `FormsDataContext` value changes, so an option is to clear the list in this case. After this change, my test passes -- but it was already passing on iOS and Android.
Apparently iOS is only creating 1: Assert.Equal() Failure\nExpected: 3\nActual: 1
jonathanpeppers
approved these changes
Mar 2, 2023
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
jsuarezruiz
approved these changes
Mar 2, 2023
mandel-macaque
approved these changes
Mar 2, 2023
/backport to release/7.0.2xx |
Started backporting to release/7.0.2xx: https://github.com/dotnet/maui/actions/runs/4469316800 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
area-controls-collectionview
CollectionView, CarouselView, IndicatorView
fixed-in-7.0.92
Look for this fix in 7.0.92!
platform/windows 🪟
t/housekeeping ♻︎
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport of #13530 to net7.0
/cc @PureWeen @jonathanpeppers