-
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
Memory leak while repeatedly navigating between pages #10578
Comments
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
At first thought, I thought this could be fixed by: #13833 But when I test the above sample, it leaks on Windows unless I make this change ( private async void Button_Clicked(object sender, EventArgs e)
{
await Navigation.PopAsync();
// Fixes the leak?
collectionView.Handler?.DisconnectHandler();
} More investigation needed on this one, there must be another issue to solve. |
Fixes: dotnet#10578 Context: https://github.com/Vroomer/MAUI-navigation-memory-leak.git After testing the above sample, I found that adding a `CollectionView` to a `Page`, makes it and the entire page live forever. This is WIP, as it is still failing on iOS/Catalyst. This fixes Android & Windows so far.
Fixes: dotnet#10578 Context: https://github.com/Vroomer/MAUI-navigation-memory-leak.git After testing the above sample, I found that adding a `CollectionView` to a `Page`, makes it and the entire page live forever. This is WIP, as it is still failing on iOS/Catalyst. This fixes Android & Windows so far.
Fixes: dotnet#10578 Context: https://github.com/Vroomer/MAUI-navigation-memory-leak.git After testing the above sample, I found that adding a `CollectionView` to a `Page`, makes it and the entire page live forever. Android & Windows: * `MauiRecyclerView` and `StructuredItemsViewHandler` respectively subscribed to `ItemsLayout.PropertyChanged`. This kept the `CollectionView` alive -> all the way up to the `Page`. * Switched to using `WeakNotifyPropertyChangedProxy` solved the issue for these two platforms. iOS: * Generally had a small "nest" of circular references. Initially, I saw `CollectionView`, `UICollectionView`, and various helper classes that would live forever. * `ItemsViewController : UICollectionViewController` -> * `ObservableItemsSource` -> * `UICollectionViewController` and `UICollectionView` * `UICollectionView` -> * `ItemsViewLayout : UICollectionViewFlowLayout` -> * `Func<UICollectionViewCell>` -> * `ItemsViewController : UICollectionViewController` -> * `UICollectionView` I switched to using `WeakReference<T>` to break the circular references. This required several null checks, where `null` references were not possible before. After these changes my tests pass, yay!
Fixes: #10578 Context: https://github.com/Vroomer/MAUI-navigation-memory-leak.git After testing the above sample, I found that adding a `CollectionView` to a `Page`, makes it and the entire page live forever. Android & Windows: * `MauiRecyclerView` and `StructuredItemsViewHandler` respectively subscribed to `ItemsLayout.PropertyChanged`. This kept the `CollectionView` alive -> all the way up to the `Page`. * Switched to using `WeakNotifyPropertyChangedProxy` solved the issue for these two platforms. iOS: * Generally had a small "nest" of circular references. Initially, I saw `CollectionView`, `UICollectionView`, and various helper classes that would live forever. * `ItemsViewController : UICollectionViewController` -> * `ObservableItemsSource` -> * `UICollectionViewController` and `UICollectionView` * `UICollectionView` -> * `ItemsViewLayout : UICollectionViewFlowLayout` -> * `Func<UICollectionViewCell>` -> * `ItemsViewController : UICollectionViewController` -> * `UICollectionView` I switched to using `WeakReference<T>` to break the circular references. This required several null checks, where `null` references were not possible before. After these changes my tests pass, yay!
Description
Recurring navigation to a page and back causes memory leak. It can lead to extreme degradation in performance in a case of an app that uses TabbedPage with complex Views that contain a lot of controls.
In the app I'm developing I have a CollectionView of items which can be opened by user to show detailed information. The user has to be able to do such action hundreds of times during a session. However there seems to be something lingering in the memory which can't be collected by GC and isn't properly disposed.
I made a simple example consisting of two pages. The app is made so that you can easily push and pop a page. The pushed page consists only of a simple CollectionView.
Steps to Reproduce
Link to public reproduction project repository
https://github.com/Vroomer/MAUI-navigation-memory-leak.git
Version with bug
Unknown/Other (please specify)
Last version that worked well
Unknown/Other
Affected platforms
Windows
Affected platform versions
Windows SDK 10.0.22000
Did you find any workaround?
No response
Relevant log output
No response
The text was updated successfully, but these errors were encountered: