Skip to content
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 control throws OutOfMemoryException on call to EnsureCoreWebView2Async() after being loaded too many times #9689

Closed
tflopez opened this issue Jun 3, 2024 · 3 comments
Labels
area-WebView bug Something isn't working closed-NotRepro Described behavior could not be reproduced. team-Controls Issue for the Controls team

Comments

@tflopez
Copy link

tflopez commented Jun 3, 2024

Describe the bug

Our WinUI 3 app allows users to navigate to various pages to define a model, compute, and review outputs. Some of these pages have WebView2 controls on them to show their content. Once we've loaded a WebView2 control 252 times, the 253rd attempt throws an OutOfMemory exception when we call EnsureCoreWebView2Async() when initializing the WebView2 control.

This was tested with the following configurations with the same behavior:

  • Windows 10 (10.0.19045), WebView Runtime 125.0.2535.67 and 124.0.2478.109
  • Windows 11 (10.0.22631), WebView Runtime 125.0.2535.67

Steps to reproduce the bug

WebViewTest.zip

  1. Run the attached application's Debug|x86 unpackaged configuration
  2. Click on a NavigationViewItem to load a page containing a single WebView2 control
  3. Continue clicking on a NavigationViewItem to load subsequent pages
  4. Once you start to load the 253rd page, it will crash with an OutOfMemoryException when the page calls the WebView2's EnsureCoreWebView2Async() method.

Expected behavior

We should be able to load and unload a WebView2 control as many times as necessary, as is possible with other controls like TextBoxes, RadioButtons, etc.

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.5.3: 1.5.240428000

Windows version

Windows 11 (22H2): Build 22621, Windows 10 (21H2): Build 19044

Additional context

If I don't call WebView.Close() from the Page's Unloaded event, I have been able to load the WebView2 control as many as 268 times before crashing.

I've made a similar bug report in the Microsoft Edge WebView2Feeback repository. Please let me know if that or somewhere else is a more appropriate place to report this issue. Thank you!

@tflopez tflopez added the bug Something isn't working label Jun 3, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Jun 3, 2024
Copy link

github-actions bot commented Jun 3, 2024

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. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@codendone codendone added area-WebView team-Controls Issue for the Controls team and removed needs-triage Issue needs to be triaged by the area owners labels Jun 13, 2024
@llongley
Copy link
Member

I've had a look at this, and it looks to me like it may be an issue with C# garbage collection. In your test app (thanks so much for that, by the way!), I added this after WebView2.Close();:

                WebView.DispatcherQueue.TryEnqueue(DispatcherQueuePriority.Normal, () =>
                {
                    GC.Collect();
                });

I no longer see the memory usage grow unboundedly larger with that added. Could you confirm? It's possible I'm missing something, so feel free to reopen if so.

@llongley llongley closed this as not planned Won't fix, can't repro, duplicate, stale Aug 20, 2024
@llongley llongley added the closed-NotRepro Described behavior could not be reproduced. label Aug 20, 2024
@tflopez
Copy link
Author

tflopez commented Sep 4, 2024

Thanks for looking at this! After you posted, I ran through some tests before trying your solution and found that I could no longer reproduce the initial issue. I loaded the WebView2-containing page more than 600 times without a crash before giving up. So, I think the problem has already been addressed in some way.

@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Sep 4, 2024
@codendone codendone removed the needs-triage Issue needs to be triaged by the area owners label Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-WebView bug Something isn't working closed-NotRepro Described behavior could not be reproduced. team-Controls Issue for the Controls team
Projects
None yet
Development

No branches or pull requests

3 participants