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
22.12k stars 1.73k forks source link

Maui causes memory leak on iOS #10801

Open AidarNurmukhametov opened 2 years ago

AidarNurmukhametov commented 2 years ago

Description

Custom view causes a memory leak. Everything works fine on Android, but on iOS it leaks. Calling DisconnectHandler on Unloaded event crashes the application. You can test this on this example. As I can see it, everything worked fine on previous version of .NET MAUI.

Is there a common way to garbage collect views/pages? Or everything must be done by .NET MAUI itself?

Steps to Reproduce

  1. Open above-mentioned project
  2. Run on iOS.
  3. On the MainPage click "Add custom control" button. The CustomTextView will be added on the page
  4. Then click "Call GC.Collect + show refs" button. Notice that ApplicationOutput have messages about CustomTextView, it is alive.
  5. Click "Remove custom control" button. The CustomTextView will be removed from the page.
  6. Сlick "Call GC.Collect + show refs" button again. Notice that CustomView is not collected, you should receive the same message as at step 4.
  7. (Optional) Try steps 3-6 on Android. Everything is collecting properly.
  8. (Optional) In another issue someone suggested to call DisconnectHandler then Unloaded event is fired. Uncomment lines 16-17 in MainPage.xaml.cs file. Try steps 2-6 and notice that application crashed.

Link to public reproduction project repository

https://github.com/AidarNurmukhametov/TestLeaks

Version with bug

7.0 Release Candidate 2

Last version that worked well

7.0 Release Candidate 1

Affected platforms

iOS

Affected platform versions

iOS 16, Xcode 14, Visual Studio for Mac 2022 Preview 17.4

Did you find any workaround?

No response

Relevant log output

No response

ghost commented 2 years ago

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.

mattleibow commented 2 years ago

Related to https://github.com/dotnet/maui/issues/1389

XamlTest commented 1 year ago

Verified this on Visual Studio Enterprise 17.7.0 Preview 4.0. Repro on iOS 16.4 .NET 8, not repro on Android 13.0-API33 with below Project: 10801.zip iOS: image

PureWeen commented 4 months ago

Can you test with the latest nightly build? https://github.com/dotnet/maui/wiki/Nightly-Builds