-
Notifications
You must be signed in to change notification settings - Fork 52
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
WebView2 memory leak #1633
Comments
Thanks for the bug report @tj-jyk! I've added it to our backlog to take a look. In the meantime do you need to remove and create a new WebView2 every time? Can you reuse the WebView2 when you need to change content? |
Hi @champnic. |
I completely agree we should try and fix this memory leak - I just wanted to make sure that your app wasn't blocked by this issue :) |
Hey @AdamCaviness - Can you share how you are hooking up to the WebView2 and how/when you are calling Dispose? |
@champnic Gladly. In my scenario, the WebView2 component is not placed in a dedicated window but is instead shown directly in the MainWindow with an active screen approach. The sample (WpfWebView2Leak) demonstrates the same single window app approach. The WebView2 component is disposed in the WebScreen Close button handler. The derived WebView2 approach is intended to address a Windows sleep issue with WebView2. I used dotMemory to profile the sample. Thanks. |
Thanks for sharing. I've verified that the WebView2 processes and most of the WebView2 code is being cleaned up at least, as those are where most of the memory usage would be. I wonder if there's a bug in WPF around making sure the HwndSourceKeyboardInputSite gets removed from the list. We'll take a closer look. Thanks! |
I'd just like to report that we have found the same issue: attaching the Webview to the UI is what causes the leak. Here is an example project (VS solution) EDIT: |
I have the same problem. |
fanioparoid |
Hello
I have a workaround: never delete the webview2 object. If you do not need the browser anymore, keep it around for next usage.
Fabio
Da: juipinjao ***@***.***>
Inviato: giovedì 6 ottobre 2022 16:37
A: MicrosoftEdge/WebView2Feedback ***@***.***>
Cc: Fabio Parodi ***@***.***>; Comment ***@***.***>
Oggetto: Re: [MicrosoftEdge/WebView2Feedback] WebView2 memory leak (#1633)
fanioparoid
I face the same problem on a MFC app. too. Just wonder if you find any solution? Thanks
—
Reply to this email directly, view it on GitHub<#1633 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ACA6FUXNYPENIHRBXOXLQ53WB3PYFANCNFSM5B3R2DSA>.
You are receiving this because you commented.Message ID: ***@***.******@***.***>>
|
The original issue posted by @tj-jyk (my colleague) seems to be solved. |
Glad to hear it's working now @agenne! For others on this thread - if you are still seeing the issue and it's not in WinUI 2.8.1 or WindowsAppSDK, please open a separate issue for us to track. Thanks! |
Description
WebView2 (and old WebView) exhibits a memory leak when creating and deleting the control in a loop. In my application, the user can change the content every (x) seconds and with a WebView/WebView2 control the user will get a memory leak. I opened already 2 Issues in WindowsAppSDK repo and in WinUI repo
Version
SDK: 1.0.902.49
Runtime: 92.0.902.62
Framework: UWP
OS: Win10 10.0.19042 Build 19042
Repro Steps
UWP Project GitHub repo
var timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1) }; timer.Tick += Timer_Tick; timer.Start();
VisualTreeHelper.GetChildrenCount(parent); ..... VisualTreeHelper.GetChild(parent, i) ...
)(VisualTreeHelper.DisconnectChildrenRecursive(rootGrid);)
webViewToRemove.Navigate(new Uri("about:blank"));
For a WebView2:webViewToRemove.Close();
rootGrid.Children.Add(newWebView);
Screenshots
Additional context
AB#35385513
The text was updated successfully, but these errors were encountered: