MicrosoftEdge / MicrosoftEdge/WebView2Feedback
Can not release webview2,memory leak
Nobody has claimed this yet.
- Dominant language
- PowerShell
- Stars
- 526
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
What happened?
use webview2 in a usercontrol
i can't release the webview2 when the usercontrol closed(remove from virtualtree)
Importance
Important. My app's user experience is significantly compromised.
Runtime Channel
Stable release (WebView2 Runtime)
Runtime Version
122.0.2365.66
SDK Version
1.0.2365.46
Framework
WPF
Operating System
Windows 10
OS Version
22621.1992
Repro steps
minium code:
public MainWindow()
{
InitializeComponent();
Loaded += MainWindow_Loaded;
}
private async void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
for (int i = 0; i < 10; i++)
{
var uc = new CCTest();
var wb = new WebView2();
uc.Content = wb;
wb.Source = new Uri("https://www.baidu.com");
g2.Children.Add(uc);
}
Console.WriteLine(CCTest.count);
await Task.Delay(100);
g2.Children.Clear();
for (int i = 0; i < 100; i++)
{
GC.Collect();
await Task.Delay(10);
}
Console.WriteLine(CCTest.count);
}
public class CCTest : ContentControl
{
public static int count = 0;
public CCTest()
{
count++;
}
~CCTest()
{
count--;
}
}
count is 10
Repros in Edge Browser
No, issue does not reproduce in the corresponding Edge version
Regression
No, this never worked
Last working version (if regression)
No response
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal MainWindow_Loaded repro and the CCTest ContentControl shown in the issue, focusing on WebView2 instances removed from g2. Investigate their lifecycle after g2.Children.Clear() and forced garbage collection; done means the reproduced controls and WebView2 resources can be released rather than remaining retained.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100