Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

Create OSR

dilfich
Posts: 330
Joined: Thu Nov 30, 2017 1:17 am

Create OSR

Post 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;
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Create OSR

Post 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.
dilfich
Posts: 330
Joined: Thu Nov 30, 2017 1:17 am

Re: Create OSR

Post 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:
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Create OSR

Post 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.
dilfich
Posts: 330
Joined: Thu Nov 30, 2017 1:17 am

Re: Create OSR

Post 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?
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Create OSR

Post 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.
dilfich
Posts: 330
Joined: Thu Nov 30, 2017 1:17 am

Re: Create OSR

Post 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..
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Create OSR

Post 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.
dilfich
Posts: 330
Joined: Thu Nov 30, 2017 1:17 am

Re: Create OSR

Post 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..
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Create OSR

Post 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.
Post Reply