dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.63k stars 1.62k forks source link

[ios/catalyst] fix memory leaks in `*Cell` #22067

Open jonathanpeppers opened 2 weeks ago

jonathanpeppers commented 2 weeks ago

Fixes: https://github.com/dotnet/maui/issues/20195 Context: https://github.com/AdamEssenmacher/MemoryToolkit.Maui/tree/main/samples

Retesting this sample with the ListView leak fixed, I noticed the sample reports 0 leaks! Unfortunately, it still displayed memory growing over time...

Taking a .gcdump snapshot, I noticed a cycle:

I was able to write a test that reproduces the leak, and I extended it for every type of *Cell like TextCell, ImageCell, SwitchCell, etc.

The fixes are:

Note that I changed PropertyChanged to an event, which is an API change. (I can revisit this if needed)

jsuarezruiz commented 1 week ago

Needs a rebase to get the updated snapshot for Issue18242Test and fix the build.