CefSharp offscreen not freeing memory

614 Views Asked by At

Based on CefSharp.MinimalExample i created similar issue to that im having in my app. I creating many browsers in background, every of them have certain tasks, and then they should close and dispose. But i noticed every offscreen browser i create, adds to used memory around 4MB, and it's something called BitmapBuffer, why it's not disposing? I am doing something wrong?

Code:

public static int Main(string[] args)
    {
        CefSharpSettings.SubprocessExitIfParentProcessClosed = true;
        CefSharpSettings.WcfEnabled = false;

        var settings = new CefSettings()
        {
            //By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data
            CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache"),
        };

        settings.CefCommandLineArgs.Add("disable-gpu-compositing", string.Empty);

        Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);

        for (int i = 0; i < 150; i++)
        {
            Thread.Sleep(1000);
            Task.Run(CreateAndDispose);
        }

        //GC.Collect(); does not change anything

        Console.ReadKey();

        return 0;
    }

    public static async Task CreateAndDispose()
    {

        var browser = new ChromiumWebBrowser("https://www.google.com/");


        browser.GetBrowser().CloseBrowser(true);
        browser.RenderHandler = null
        browser.Dispose();
        browser = null;


    }

Memory view of an exmaple

EDIT: Instead of 10 i created 150 instances of offscren browser, because i thought 80 mb of used memory is too low for GC to care, but it didn't changed anything and now it's 800mb of used memory with same problem.

I launched example 3-4 times, and waited 10 to 20 minutes for memory to free with same result.

Memory view and it change after some time

Memory view after 16 minutes

0

There are 0 best solutions below