[Problem/Bug]: Memory leak on WebResourceResponseReceived event listener
What happened?
I can see memory usage of the webview renderer processes steadily go up throughout the day when I use this event listener. I need to use this event listener in order to get the content of HTTP requests made by my webapps.
Even setting up an empty event listener triggers the memory growth.
Importance
Blocking. My app's basic functions are not working due to this issue.
Runtime Channel
Stable release (WebView2 Runtime)
Runtime Version
133.0.3065.92
SDK Version
1.0.3065.39
Framework
Winforms
Operating System
Windows 10
OS Version
10.0.194045
Repro steps
Set up any WebResourceRequestedFilter and an event listener on WebResourceResponseReceived:
webView.CoreWebView2.AddWebResourceRequestedFilter("*", CoreWebView2WebResourceContext.All)
webView.CoreWebView2.WebResourceResponseReceived += OnWebResourceResponseReceived;
private void OnWebResourceResponseReceived(object sender, CoreWebView2WebResourceResponseReceivedEventArgs e)
{
return;
}
Observing memory usage of renderer process over time (especially with web applications with lots of network requests).
Repros in Edge Browser
No, issue does not reproduce in the corresponding Edge version
Regression
Don't know
Last working version (if regression)
No response
Internal Tracking Number: 57210024
have you notice this issue in the previous versions as well ? or just this version ?
also possible that you are not unsubscribing to the event correctly maybe ?
example :
// Unsubscribe when disposing or no longer needed
webView.CoreWebView2.WebResourceResponseReceived -= OnWebResourceResponseReceived;
or when Disposing
public void Dispose()
{
if (webView?.CoreWebView2 != null)
{
webView.CoreWebView2.WebResourceResponseReceived -= OnWebResourceResponseReceived;
}
webView?.Dispose();
}
and make sure you are not Subscribing to the event ( += ) inside a loop , or any interval kind of method .
have you notice this issue in the previous versions as well ?
Yes. I was using runtime version 103 when I noticed this. Then upgraded to latest stable version and I see it's still happening.
also possible that you are not unsubscribing to the event correctly maybe ?
I am subscribing only once, and unsubscribing correctly on webview disposal. I have a bunch of other event handlers I subscribe / unsubscribe in the same way and none of them cause problems.
We observed the same thing (and stopped using WebResourceResponseReceived as a result). Here were the symptoms we observed:
- lots of memory allocations containing HTTP headers (SysInternals VMMap showed the memory as non-heap allocations colored yellow)
- there was an unused VM page between each chunk of memory containing HTTP headers
- it didn't happen with plain HTTP requests (seemed to be something more exotic like XHR or web sockets, so it didn't happen on every site)