Memory management

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.

Memory management

Postby deividmarinho » Sun Jan 21, 2018 2:03 pm

I'm work with CefSharp Winforms (v57.0.0) in my C# Winform application (.NET 4.5.2), and it's been working well...

As I have to do several access to sites, the CEF Browser process consumes a lot of memory! I've already researched in the documentation and in other forums about it but I didn't get a satisfactory answer... The "best" solution, until now, is restart the program.

Is there any way to "clear" the memory usage by CEF Browser process without restarting my program?

Follow the code of Cef initialization:

Code: Select all
     
CefSettings settings = new CefSettings();
settings.CachePath = Program.CACHE_PATH; // cache path
settings.IgnoreCertificateErrors = true;
settings.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36";
settings.PersistSessionCookies = false;
// Initialize cef with the provided settings
bool initialized = false;
string cefError = string.Empty;
try
{
   Thread.Sleep(1000);
   initialized = Cef.Initialize(settings, true, null);
}
catch (Exception ex)
{
   cefError = ex.InnerException == null ? ex.Message : ex.InnerException.InnerException == null ? ex.InnerException.Message : ex.InnerException.InnerException.Message;
}

if (!initialized)
{
  // ERROR! => FINISH PROGRAM
  // ...
  return;
}

// Cookies path
Cef.GetGlobalCookieManager().SetStoragePath(Program.COOKIES_PATH, false);

// Create a browser component
webBrowser = new ChromiumWebBrowser("about:blank");
webBrowser.Name = "WebBrowser";
webBrowser.TabIndex = 0;
webBrowser.BrowserSettings.ApplicationCache = CefState.Disabled;
webBrowser.BrowserSettings.FileAccessFromFileUrls = CefState.Enabled;
webBrowser.BrowserSettings.UniversalAccessFromFileUrls = CefState.Enabled;
webBrowser.BrowserSettings.ImageLoading = CefState.Disabled;
webBrowser.BrowserSettings.Javascript = CefState.Enabled;
webBrowser.BrowserSettings.WebSecurity = CefState.Disabled;
webBrowser.KeyboardHandler = new BrowserChrome.KeyboardHandler(); // prevent keyboard
webBrowser.JsDialogHandler = new BrowserChrome.JsHandler(); // prevent alerts

// Add to tab (tabBrowser is a TabPage)
tabBrowser.Controls.Add(webBrowser);

webBrowser.Dock = DockStyle.Fill;



And where it ends the program has the following code:

Code: Select all
 Cef.Shutdown();
deividmarinho
Newbie
 
Posts: 1
Joined: Sun Jan 21, 2018 1:32 pm

Re: Memory management

Postby Czarek » Wed Jan 24, 2018 3:43 pm

Have you tested how CEF cefclient application behaves for these websites? Some options/switches may increase memory usage by not allowing to share renderer processes for sites. You should ask this question on CefSharp support channel, see the project's README.
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


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 38 guests