Replies: 1 comment
-
Closed as per the Community Stand-up discussion here: https://youtu.be/N9wMcBP4jtg?t=2889 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The "Problem"
On our toolkit, we followed the pattern, also promoted by me, of disposing of Controls ASAP, at first glance that looks like the correct approach to follow and that was the Xamarin.Forms (XF) way to do it and that has its issues.
On .NET MAUI this behavior has changed, so now the framework doesn't call
Dispose
orDisconnectHandler
on controls ASAP, the clean-up is the user's (dev) responsibility. And the reason for that is:So for example, let's say that our user has a MediaPlayer application and uses our
MediaElement
control and a Player page is created when the user selects a media to run. Now imagine the user navigates to another page inside the application, from our current implementation theMediaElement
will be disposed of, meaning theMediaElement
control (shared and platform-specific areas) will be destroyed. With that, the media will stop playing. Can you see the issue?Probably the desired behavior is to have the player still alive and playing the media. But with the current pattern that we have that isn't possible. (For a more complete discussion around this, please see this discussion.
Another situation that could happen, is the user wants to cache a Popup, that isn't possible today due to our pattern, as you can see here.
Another issue that I see during our implementation is to implement
destructors
on classes which isn't very safe... And, IMHO, if the .NET MAUI (a way complex project than ours) doesn't use it, we shouldn't use it as well. Friendly reminder that when we callGC.SuppresFinilizer
we extend the life of that object.Solution
We shouldn't call the
Dispose
and/orDisconnectHandler
so agressively, we should follow the same behavior as .NET MAUI , that way the user will experience the same behavior accross our lib and the MAUI framework.Drawbacks
This will be a breaking change, since the lifecycle of controls will change drastically causing issues and fake memory leaks. Sadly there's no docs or a guide on how devs should handle that (yet), as you can see there's an open issue to track it.
Beta Was this translation helpful? Give feedback.
All reactions