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

Memory leak when data isn't read in WebMessageReceived #3794

Closed
avendel opened this issue Sep 19, 2023 · 2 comments
Closed

Memory leak when data isn't read in WebMessageReceived #3794

avendel opened this issue Sep 19, 2023 · 2 comments
Assignees
Labels
bug Something isn't working tracked We are tracking this work internally.

Comments

@avendel
Copy link

avendel commented Sep 19, 2023

Description

When the top-level document of the WebView runs window.chrome.webview.postMessage, and no code in the host process reads the message data, memory is allocated but never released.

Version
SDK: 1.0.2045.28
Runtime: 117.0.2045.31
Framework: WinForms, .NET Framework 4.8.1
OS: Win11

Regression
Don't know whether this is a regression.

Repro Steps

The fastest way of seeing this behavior is to call postMessage with a large data object, like in the example below.

<script lang="javascript">
    function sendMessageToHost() {
        window.chrome.webview.postMessage(new Array(90000));
    }

    setInterval(sendMessageToHost, 100);
</script>

Then in the hosting .NET code, either don't add an event handler for CoreWebView2.WebMessageReceived, or don't read the message json.

this.webView.NavigateToString(html);
this.webView.CoreWebView2.WebMessageReceived += (sender, e) => {
    // Without executing the line below, memory is allocated but never released.
    //this.LastMessage = e.WebMessageAsJson;
};

The host process leaks unmanaged memory.

AB#46620265

@avendel avendel added the bug Something isn't working label Sep 19, 2023
@yildirimcagri-msft yildirimcagri-msft added the tracked We are tracking this work internally. label Sep 19, 2023
@yildirimcagri-msft
Copy link
Member

Thanks for reporting this, we have a fix in the works.

@yildirimcagri-msft
Copy link
Member

yildirimcagri-msft commented Oct 18, 2023

The fix will be available in the next SDK release. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests

3 participants