Page 2 of 2

Re: CEF JavaScript binding "require/import" question

PostPosted: Thu Jul 15, 2021 10:17 pm
by amaitland
Quite some time ago `CefSharp` used `CefRegisterExtension` to inject a function into every V8 context, it was a simple script to create a promise.

`Eval` would later be called to execute the function without params. This would leak memory.
Executing the script directly using `Eval` and the memory leak went away.

Way back in M65 `CefRegisterExtension` would leak memory.

Re: CEF JavaScript binding "require/import" question

PostPosted: Fri Jul 16, 2021 6:12 am
by Czarek
Devyre wrote:
Code: Select all
<!DOCTYPE html>
<html>
    <head>

    </head>
    <script>
        setTimeout(async () => {
         while (true)
            NativeCall();
      }, 5000);
    </script>
    <body>
        <div>test</div>
    </body>
</html>




I see an infinite loop which blocks Renderer. Why would you expect it to work?

Re: CEF JavaScript binding "require/import" question

PostPosted: Fri Jul 16, 2021 10:08 am
by Devyre
It was a stress test. I expected it to work because it works in any modern browser.
The problem wasn't high cpu usage or the renderer process being locked up, it was crashing almost instantly because of an out of memory exception (with less than 40MB ram allocated). That shouldn't happen.

This was confirmed to be due to the usage of CefRegisterExtension, as I wrote in my last post:
Devyre wrote:I should have listened to you when you told me not to use extensions.
This issue is because of extensions, 100% confirmed.

I just added my NativeCall to the window object instead of registering an extension, and the exact same code, even the first one, now works perfectly fine.
It also seems to execute significantly faster than extensions.

Memory usage no longer increases to infinity, unless I use the first snippet (the tight while true loop).
But in that case, the JavaScript GC does its job and collects the garbage once I reach about 28MB ram.