WebView2Feedback icon indicating copy to clipboard operation
WebView2Feedback copied to clipboard

[Problem/Bug]: Memory leak on WebResourceResponseReceived event listener

Open lcornelatti opened this issue 9 months ago • 3 comments

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

lcornelatti avatar Mar 05 '25 16:03 lcornelatti

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 .

nasusonetrick avatar Mar 06 '25 12:03 nasusonetrick

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.

lcornelatti avatar Mar 06 '25 13:03 lcornelatti

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)

dd8 avatar Nov 03 '25 15:11 dd8