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.
Fixes a memory leak explained in #1242:
Pull request type
Please check the type of change your PR introduces:
What is the current behavior?
ListView leaks memory due to
RemoveValueChanged
is never called and the dangling reference to the control is being hold forever.Issue Number: #1242
What is the new behavior?
Unloaded
event and removes the subscription toValueChanged
event of the View.Other information
A basic unit test which displays the difference between WpfUi's ListView vs regular ListView in terms of being successfully collected by GC
Before:
After:
I'd also like to recommend adding some basic unit-tests that would test (almost) all controls to ensure that the same basic mistake is not repeated in a future
This test finds all classes that are assignable to Control from Wpf.Ui. namespace that have parameterless constructor and make an attempt to perform the same test that was used for the
ListView
in the previous code listing.Fun fact: in addition to ListView, it also reports
DataGrid
to also have a memory leak. I didn't dig into it so it could be some false positive, which doesn't happen in real life scenario, but what I could tell is that the issue was related specifically to the components used withinDataGrid.xaml
(commenting out entire markup fixed the unit test).Aforementioned unit test are not included in the PR (doesn't look like there are many in this repo at all), but I can commit the as well if requested.