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();