-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Labels
area-controls-listviewListView and TableViewListView and TableViewperf/memory-leak 💦Memory usage grows / objects live forever (sub: perf)Memory usage grows / objects live forever (sub: perf)platform/iost/bugSomething isn't workingSomething isn't working
Milestone
Description
Description
I'm seeing memory leaks regarding the ListView control in .NET 8/9. The issue appears on iOS when using ListViewCachingStrategy.RecycleElement, and is much worse when using this CachingStrategy with HasUnevenRows="true".
I have been unable to test on Android on .NET 9 but on .NET 8 (MAUI 8.0.93) I did not see this.
Popping the page with this markup will result in the entire Page remaining in memory.
<ListView HasUnevenRows="True"
CachingStrategy="RecycleElement">
<!-- Just using CachingStrategy="RecycleElement" produces some memory leaks
but not as much as both together-->
<ListView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>0</x:String>
<x:String>1</x:String>
<x:String>2</x:String>
<x:String>3</x:String>
<x:String>4</x:String>
<x:String>5</x:String>
<x:String>6</x:String>
<x:String>7</x:String>
<x:String>8</x:String>
<x:String>9</x:String>
</x:Array>
</ListView.ItemsSource>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding .}"/>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
The reproduction I have done does not use Shell.
Steps to Reproduce
- Create a new .NET 9 MAUI App
- Define a static collection of
WeakReference
to track leaky views - Add a new Page and a button to push the page to the navigation stack
- In the new page, add a ListView with
HasUnevenRows="True"
andCachingStrategy="RecycleElement"
. - Either Bind or set the
ItemsSource
and define a simpleItemTemplate
- Add each item in the VisualElements to the leaky view collection when the page is disappearing
- Open the app
- Push and pop the page
- Force Garbage Collection
- See your leaky views remain in memory
You can see my reproduction repo, you can:
- Hit 'Open Leaks Issue # 1'
- Go back
- Hit 'Collect Garbage' a couple of times
- Hit 'Check References'
- See the alive references
Doing the same for Leaks Issue # 2 produces more leaky views.
Link to public reproduction project repository
https://github.com/NeilMalcolm/ListViewMemoryRepro
Version with bug
9.0.21 SR2.1
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
iOS
Affected platform versions
No response
Did you find any workaround?
Not setting the CachingStrategy seems to resolve the issue.
Relevant log output
onoda-takashi-bos
Metadata
Metadata
Assignees
Labels
area-controls-listviewListView and TableViewListView and TableViewperf/memory-leak 💦Memory usage grows / objects live forever (sub: perf)Memory usage grows / objects live forever (sub: perf)platform/iost/bugSomething isn't workingSomething isn't working