-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Win platform WebView cannot be release after its parent window get close #22972
Comments
Hi I'm an AI powered bot that finds similar issues based off the issue title. Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you! Open similar issues:
Closed similar issues:
|
Verified this issue with Visual Studio 17.11.0 Preview 1.1 (8.0.40 & 8.0.21). Can repro on windows platform with sample project. |
@mattleibow @jsuarezruiz @PureWeen |
@jingliancui for now, can you do something like this in your protected override void OnDisappearing()
{
base.OnDisappearing();
webView.Handler?.DisconnectHandler();
} (I put This seems to solve the issue in this sample: |
Fixes: dotnet#20283 Fixes: dotnet#22972 Context: https://github.com/davide-cavallini/webview-winUI-maui-leak The above sample on Windows was leaking because it does the following: 1. Your app has a single `Window` 2. Navigate to a page with a `WebView` 3. Navigate away Because the `Window` remains alive, `WebViewHandler` subscribes to `Window.Closed` which keeps a reference to the `WebView` and keeps it alive indefinitely. I was able to reproduce this in a test, that keeps the `Window` alive before calling `AssertionExtensions.WaitForGC()`. The solution was to move the `Window.Closed` subscription to the `WebView2Proxy` nested class. This makes sure that the `WebView`, its handler, etc. can be collected *before* the `Window` is closed. I also found a secondary issue while debugging, if you call: webView.Close(); // MauiWebView or WebView2 If `CoreWebView2` is not initialized, it will throw a C++ exception. We can instead do: if (webView.CoreWebView2 is not null) { webView.Close(); }
Hi @jonathanpeppers not sure which platformview cause this exception |
@jonathanpeppers You can try my sample repo, it also can reproduce the exception, even I updated the nuget to latest version. |
This has the fix for the underlying problem, if you are interested: It would no longer require |
Cool! May I know if the fix will be released at next sr8? Thanks |
Description
Please see the Reproduce
Steps to Reproduce
Expect result:
Memory should be reduced
Actual result:
Memory does not get reduced
Link to public reproduction project repository
https://github.com/jingliancui/MAUIWebViewMultipleWinIssue
Version with bug
8.0.40 SR5
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Windows
Affected platform versions
windows10.0.19041.0
Did you find any workaround?
no
Relevant log output
The text was updated successfully, but these errors were encountered: