Page 1 of 2

Create OSR

Posted: Mon Feb 12, 2018 8:26 am
by dilfich
I create 20 pieces of OSR, after 10 hours of work take about 3GB of memory, is it normal or am I doing it wrong?

Code: Select all

procedure Chrom.CreateOSR(Thrd: Integer);
var
  TempContext : ICefRequestContext;
begin
  ChromOSR[Thrd]:= TChromium.Create(nil);
  ChromOSR[Thrd].Name:= 'ChromOSR' + IntToStr(Thrd);
  ChromOSR[Thrd].Tag:= Thrd;
  ChromOSR[Thrd].DefaultUrl:= 'about:blank';

  ChromOSR[Thrd].OnBeforePopup:= Form1.ChromOSRBeforePopup;
  ChromOSR[Thrd].OnJsdialog:= Form1.ChromOSRJsdialog;

  TempContext := TCefRequestContextRef.New('', 'ru', False, False, False, False);

  ChromOSR[Thrd].CreateBrowser(nil, '', TempContext);
end;

Re: Create OSR

Posted: Mon Feb 12, 2018 8:49 am
by salvadordf
I haven't tried to keep running a browser for that long. :shock:

Use FastMM4 to know if there's a memory leak or try an alternative memory manager for Delphi.

Re: Create OSR

Posted: Wed Feb 14, 2018 7:39 am
by dilfich
How to determine the readiness of the browser to work after creating it?
And then on slower machines it is not clear when it can be used. :shock:

Re: Create OSR

Posted: Wed Feb 14, 2018 8:34 am
by salvadordf
You can only call TChromium.CreateBrowser after GlobalCEFApp.GlobalContextInitialized is set to True and GlobalCEFApp.GlobalContextInitialized is set to True right before the GlobalCEFApp.OnContextInitialized event is triggered.

There are a couple of ways to know when you can call TChromium.CreateBrowser :
  • The best way would be to use the GlobalCEFApp.OnContextInitialized event but it's a little complicated because that event is triggered in a different thread and it can be executed before or after the main form is created. You could use a critical section to synchronize that event with the TForm.OnShow event where the TChromium.CreateBrowser function is usually called.
  • If you want a simple but effective solution you could also use a timer. All the demos use that solution to keep them as simple as possible.

Re: Create OSR

Posted: Sat Feb 17, 2018 5:44 am
by dilfich
dilfich wrote: Mon Feb 12, 2018 8:26 am I create 20 pieces of OSR, after 10 hours of work take about 3GB of memory, is it normal or am I doing it wrong?
Made a cache on the disk, now memory is an order of magnitude less.
If we have the ability to clear the cache while you work?

Re: Create OSR

Posted: Sat Feb 17, 2018 7:56 am
by salvadordf
dilfich wrote: Sat Feb 17, 2018 5:44 amIf we have the ability to clear the cache while you work?
No. It's not possible to delete the cache while your app is running. Try deleting it before calling GlobalCEFApp.StartMainProcess.

Re: Create OSR

Posted: Sat Feb 17, 2018 9:22 am
by dilfich
salvadordf wrote: Sat Feb 17, 2018 7:56 am
dilfich wrote: Sat Feb 17, 2018 5:44 amIf we have the ability to clear the cache while you work?
No. It's not possible to delete the cache while your app is running. Try deleting it before calling GlobalCEFApp.StartMainProcess.
That is, if the path to the cache is specified here GlobalCEFApp, but if it is listed after the run in TCefRequestContextRef.New?
GlobalCEFApp.DeleteCache then not helps..

Re: Create OSR

Posted: Sat Feb 17, 2018 9:39 am
by salvadordf
When you set GlobalCEFApp.DeleteCache to True before calling GlobalCEFApp.StartMainProcess then GlobalCEFApp will delete the GlobalCEFApp.cache directory before initialization.

As far as I know, CEF3 doesn't allow to delete the cache contents while it's initialized.

I've never tried to delete the cache using different contexts and closing all the browsers using them but I wouldn't be surprised if some processes remain in memory locking the cache.

Re: Create OSR

Posted: Sun Feb 18, 2018 6:54 am
by dilfich
Decided to disable the cache, but that doesn't work, what's wrong?
Options.ApplicationCache:= STATE_DISABLED;
or
GlobalCEFApp.AddCustomCommandLine('--disable-application-cache');
GlobalCEFApp.AddCustomCommandLine('--disable-cache');
GlobalCEFApp.AddCustomCommandLine('--disable-gpu-program-cache');
GlobalCEFApp.AddCustomCommandLine('--disable-gpu-shader-disk-cache');
Folder with cache up to +- 4Gb growing..

Re: Create OSR

Posted: Sun Feb 18, 2018 7:47 am
by salvadordf
Clear the GlobalCEFApp.cache and GlobalCEFApp.cookies properties. Set them to ''.

Build your app but before you click run, delete the cache directory.