cefsharp offscreen无法释放内存
基于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;
}
编辑: 我没有创建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;
}
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论