CEF JavaScript binding "require/import" question

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Re: CEF JavaScript binding "require/import" question

Postby amaitland » Thu Jul 15, 2021 10:17 pm

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.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1290
Joined: Wed Jan 14, 2015 2:35 am

Re: CEF JavaScript binding "require/import" question

Postby Czarek » Fri Jul 16, 2021 6:12 am

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?
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: CEF JavaScript binding "require/import" question

Postby Devyre » Fri Jul 16, 2021 10:08 am

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.
Devyre
Techie
 
Posts: 27
Joined: Fri Nov 20, 2020 8:31 pm

Previous

Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 34 guests