cefsharp offscreen无法释放内存

发布于 2025-02-03 14:28:12 字数 1734 浏览 2 评论 0原文

基于cefsharp.minimalexample,我创建了与我在应用中遇到的类似问题。我在后台创建许多浏览器,每个浏览器都有某些任务,然后他们应该关闭并处置。但是我注意到我创建的每个屏幕上的浏览器,都会添加到4MB左右的内存中,这就是所谓的BitMapBuffer,为什么它不处置?我做错了什么?

代码:

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;


    }

exmaple的内存视图

编辑: 我没有创建150个Offscren浏览器的实例,因为我认为80 MB的二手内存太低了,以至于GC无法照顾任何东西,但是它没有改变任何东西,现在它是800MB的二手内存,同一问题。

我启动了3-4次示例,然后等待10到20分钟才能免费以相同的结果释放。

内存视图,并且在某个时间后它变化

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文