WindowsAppSDK icon indicating copy to clipboard operation
WindowsAppSDK copied to clipboard

WebView/WebView2 memory leak

Open tj-jyk opened this issue 5 years ago • 3 comments

Describe the bug

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.

Steps to reproduce the bug

Steps to reproduce the behavior: GitHub repo

  1. Start a loop / a timer var timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1) }; timer.Tick += Timer_Tick; timer.Start();
  2. In a loop logic find the old WebView/WebView2 control in a DOM VisualTreeHelper.GetChildrenCount(parent); ..... VisualTreeHelper.GetChild(parent, i) ...)
  3. Remove the old WebView from the DOM (VisualTreeHelper.DisconnectChildrenRecursive(rootGrid);)
  4. For a WebView call webViewToRemove.Navigate(new Uri("about:blank")); For a WebView2: webViewToRemove.Close();
  5. Add a new WebView/WebView2 control to the DOM rootGrid.Children.Add(newWebView);
  6. Application crashes after 15 minutes.

Screenshots

image

Version Info

NuGet package version:

Windows 10 version Saw the problem?
Insider Build (xxxxx)
May 2020 Update (19042) Yes
November 2019 Update (18363)
May 2019 Update (18362)
October 2018 Update (17763)

Additional context

tj-jyk avatar Aug 02 '21 10:08 tj-jyk

I can reproduce, it crashes after 20 minutes.

ghost avatar Aug 02 '21 10:08 ghost

Hi @tj-jyk, we're monitoring the issue that was opened in the WinUI repo. If the issue isn't able to be resolved with their advice we recommend that you open an Issue in the WebView2 repo

btueffers avatar Aug 06 '21 20:08 btueffers

Hi @tj-jyk, thank you for opening the issue under the MicrosoftEdge organization.

btueffers avatar Aug 16 '21 19:08 btueffers