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
MauiApp is not Disposed #20350
Comments
https://github.com/drasticactions/MauiRepros/tree/main/DisposeTest Doing this in a regular MAUI app causes the same behavior to occur. MauiApp is disposable, but nothing I can find so far shows that anything invokes it to be disposed of upon app close. If anything, MauiApp is created and its references are used to build Now, that seems kinda weird to me (Why make the object just to create a new thing off of it and throw it away) but as for Dispose itself, I don't think this is a bug. To me, that makes sense: Your app is closing. The resources you were using are going to be released anyway. Calling disposed doesn't make sense there. And if you were doing logic within your app in its Disposed methods to handle when the app is closing... I would rethink that approach. If you were using MAUI in an embedded app case, where you create MauiApp yourself and control its existence, being able to dispose it at will makes sense, as you may only need it for a specific part of your app. But for the general case of a MAUI or MAUI Blazor app, you would never dispose MauiApp yourself as that would break your app altogether, and disposing it when the app is closed, to me, doesn't make sense as your app is closing and those resources are going to be released anyway. @jonathanpeppers @mattleibow What do ya'll think? |
@drasticactions I have to say that your answer is pretty... confusing/surprising at least.
I thought it was obvious this is a minimal reproduction code that does not doing anything meaningful - just reproducing the error. I've added singleton service that needs to be disposed and it is not.
Really? Disposing object needs rethinking? I can agree that I shouldn't put long running code in disposal but not with that. In asp net core or in console app that uses |
We do and we miss graceful/orderly shutdown of our MAUI app very much. Basically user clicks "X" button and we would like to have an opportunity to dispose stuff. There is this PR #13424 but it seems like there is no good moment for us to call We would appreciate to terminate a TCP connection to another APP, some websockets, etc. This is IMO a valid intention, even if it is not 100 per cent successful in practice (everybody knows that). Honestly, I don't see this "cannot easily dispose" as a feature. |
I'm sorry! I wasn't talking about your example, I was talking about the MAUI code (As in, code in this repo)! maui/src/Core/src/Platform/Windows/MauiWinUIApplication.cs Lines 32 to 36 in 96288c1
This specifically creates a MauiApp object, but then doesn't store it anywhere. Even if you wanted to dispose it, you couldn't unless you went out of your way to do so (By storing the MauiApp when it's created within the individual platform code). I wasn't talking about your sample, what you did was 100% fine. I should have been more clear. |
Indeed, in normal circumstances app termination is 'violent' - that is, it is both sudden and catastrophic. Very little is cleaned up because the idea is to quickly make the app go away. If anything was truly important, it should have already been done (data was saved, messages sent, etc.). So why does MauiApp bother with IDisposable? For testing purposes only, really. I mean, you could probably cause it to be disposed with some extra code in your app, so long as you're aware that it still might not get called (process can be easily terminated without any code in the target process being run). |
Here's a related PR where I added IAsyncDisposable support, but also only for testing purposes: #13424 |
@Eilon I have to disagree - especially in terms of maui-blazor for windows and also generally for windows gui desktop apps. For GUI desktop apps in general - the "violent termination" is not a normal circumstance - its an exceptional case. For example in most apps when you click Maybe for IOS/Android thats the requirements and that systems forces app to quit immediately, but if MAUI app targets windows platforms then I guess Disposing MauiApp would be really beneficial. |
@malciin I think that the scenarios you describe are valid, but I'm not sure they're part of "disposing the MauiApp object". If an app wants to ask the user whether to save/upload/re-combobulate when they try to close the app, then that specific scenario should be handled as part of the "closing the window" event (whatever it might be called). |
To me thats what Lets put it differently. Why Console app that uses
So lets make |
I've given this some more thought and it could be worth considering. For anyone interested in this, I have two questions:
I think if we can come up with reasonable answers for these then it's worth giving it a shot. |
Verified this issue with Visual Studio 17.10.0 Preview 5 ( 8.0.21 &8.0.0-rc.2.9530).I can repro this issue. |
Description
I have noticed that all of my
Singleton
services are not properly disposed in my app. Upon further investigation I've noticed thats probably (I'm newbie in maui) because neither of:maui/src/Core/src/Hosting/MauiApp.cs
Line 38 in a6c9997
maui/src/Core/src/Hosting/MauiApp.cs
Line 46 in a6c9997
was called.
Steps to Reproduce
Results: Dispose never gets called thus breakpoint never occur.
Reproduction repo: malciin/maui-blazor-dispose-issue@e031693
Link to public reproduction project repository
malciin/maui-blazor-dispose-issue@e031693
Version with bug
8.0.3
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Windows, I was not able test on other platforms
Affected platform versions
No response
Did you find any workaround?
No response
Relevant log output
No response
The text was updated successfully, but these errors were encountered: