Memory leak with ExecuteScriptAsync

Having problems with building or using the CefSharp .NET binding? Ask your CEF-related questions here. Please ask general usage questions on StackOverflow.

Moderator: amaitland

Memory leak with ExecuteScriptAsync

Postby guoxiaojun » Mon Jan 04, 2021 4:51 am

I need a lot of ExecuteScriptAsync calls, and the script is different each time, for example:

Code: Select all
            var random = new Random();
            for (int i = 0; i < 100; i++)
            {
                var msg = "[this is a big string]AAAAAAAAAAAAAAAAAAAAAAAAAA" + random.Next(0, 1000000000);
                _browser.ExecuteScriptAsync("InteropBridge.getData(\"" + msg + "\")");
            }


I find the scripts can't dispose in the broswer through take the heap snapshot , how can i solve this problem?
This is tested base on cef 63 and cef 83
guoxiaojun
Newbie
 
Posts: 3
Joined: Mon Jan 04, 2021 4:10 am

Re: Memory leak with ExecuteScriptAsync

Postby amaitland » Mon Jan 04, 2021 5:55 pm

Calling ExecuteScriptAsync in a tight loop should be avoided as it's been my observation the v8 garbage collector never has a chance to run.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1290
Joined: Wed Jan 14, 2015 2:35 am

Re: Memory leak with ExecuteScriptAsync

Postby guoxiaojun » Tue Jan 05, 2021 9:33 pm

That code in the for statement is just for expression that there are many calls, It's not actually a continuous call, i take the heap snapshot and found the script never dispose, if it takes a long time to run a lot of different script , such as acommunication message, and the render process was crashed. i just want to know how to dispose the ExecuteScriptAsync function args string in the broswer, it can not be collected by the V8 garbage collector
guoxiaojun
Newbie
 
Posts: 3
Joined: Mon Jan 04, 2021 4:10 am

Re: Memory leak with ExecuteScriptAsync

Postby amaitland » Tue Jan 05, 2021 10:20 pm

ExecuteScriptAsync calls https://magpcss.org/ceforum/apidocs3/projects/(default)/CefFrame.html#ExecuteJavaScript(constCefString&,constCefString&,int) which I believe uses
https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/public/web/web_local_frame.h;l=316?q=blink::WebLocalFrame&ss=chromium, so we're reliant on the Chromium implementation,

How does it behave if you execute the same script in DevTools? If DevTools works then you can use potentially use the DevTools protocol to execute your script.

You may need to consider a different approach, sending large chunks of data it's better to use AJAX and have the browser request the data than it is to push data into the browser.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1290
Joined: Wed Jan 14, 2015 2:35 am

Re: Memory leak with ExecuteScriptAsync

Postby guoxiaojun » Wed Jan 06, 2021 3:43 am

I'm not use AJAX because the calling direction is from native to JS.
I execute the script in the DevTool and take the snap after collect garbage and i found the script not collected, so the DevTools protocol can not solve the problem.
Now we used websocket to solve this problem, and it works well.

Thank you for your reply.
guoxiaojun
Newbie
 
Posts: 3
Joined: Mon Jan 04, 2021 4:10 am


Return to CefSharp Forum

Who is online

Users browsing this forum: No registered users and 13 guests