可能的一个过程,导致泄漏的内存也被杀害后? [英] possible for a process to result in leaked memory after it is killed?

查看:197
本文介绍了可能的一个过程,导致泄漏的内存也被杀害后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写产卵和杀死一个Chrome浏览器的应用程序。虽然我杀的过程编程(相同的效果,通过Windows任务管理器杀进程),它被认为,这也可能导致内存泄漏 - 即从要素如不正确关联瓦特/原始程序内核资源

I'm writing an application that spawns and kills a Chrome Browser. While I'm killing the process programatically (same effect as killing process through Windows Task Manager), it's been suggested that this may also result in memory leak--ie from elements such as kernel resources that were not properly associated w/ the originating process.

是否有可能为应用程序内存泄漏或以其他方式不能恢复记忆的过程已被杀害后?

Is it possible to for an application to leak memory or otherwise have irreclaimable memory after the Process has been killed?

推荐答案

在任务管理器终止进程,直接会导致内存泄漏。 一个证据是保持杀的explorer.exe会拖慢整个操作系统。

Killing a process in task manager directly could result in memory leak. An evidence is keeping killing "explorer.exe" will slow down the entire OS.

每个浏览器窗口中有一个GUI程序和后台进程的每一个活动标签。后台进程是reponsible用于获取网页内容,发送请求/发送的数据,并保持超过GUI进程更少的内核对象句柄。 任何编程框架将至少有两种方法来关闭一个主动的过程。例如,在.NET中,过程类有两种方法:

Each Chrome window has a GUI process and a background process for each active tab. Background processes is reponsible for fetching page content, sending request / posting data, and hold fewer kernel object handles than GUI processes. Any programming framework will have at least two methods to close an active process. For example, in .NET, Process class has these two methods:

  1. CloseMainWindow()
    • 发送一个WM_QUIT消息到主窗口消息循环,要求关闭该进程。这使该方案有机会重新调用它的子窗口,它的内核对象。
  1. CloseMainWindow()
    • Sends a WM_QUIT message to the main window message loop to request to close the process. This gives the program a chance to reinvoke its child window and its kernel objects.
  • 在强制终止一个进程,同样在任务管理器终止进程。这是关闭后台进程的唯一途径。但是当这适用于GUI进程,这不会触发所有的GUI /内核事件以释放资源。内核对象包括GDI对象,文件/打印机在处理,数据库/网络连接上下文等。 释放这些资源需要一段时间,而跟踪整个内存链表/图来释放内核对象的资源。 即使.NET / Java有它的垃圾收集器释放托管记忆肯定的,内核对象的非托管资源并不总是包括在内。
  • Forces a termination of a process, same as killing the process in task manager. This is the only way to close background process. but when this applies to GUI processes, this doesn't trigger all GUI/kernel events to release resources. Kernel objects include GDI objects, file/printer handles, database/network connection contexts, etc. Releasing these resources take some time while tracking down the entire memory linked list/map to deallocate kernel objects' resources. Even .NET/java has its garbage collector to release "managed" memory for sure, kernel objects' unmanaged resources are not always covered.

下面是.NET C#中的测试程序。我们可以比较CloseMainWindow()来杀死()使用Visual Studio的插件:内存分析器。在几乎所有情况下,杀()速度更快,但有少检查根参考和实例引用实时图形内存释放内存。

The following is a test app in .NET C#. We can compare CloseMainWindow() to Kill() using a Visual Studio add-on: Memory Profiler. In almost all cases, Kill() is faster but has less memory released by checking "root references" and "instance references" in real-time memory graph.

private Process _chromeProcess = new Process();

private void bntCreate_Click(object sender, EventArgs e)
{
    string chromePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
        @"Google\Chrome\Application\chrome.exe");

    _chromeProcess.StartInfo = new ProcessStartInfo(chromePath, @"-app=http://localhost:(a local Web site)");
    _chromeProcess.Start();
}

private void btnKill_Click(object sender, EventArgs e)
{
    _chromeProcess.Kill();
    _chromeProcess.WaitForExit();
    _chromeProcess.Close();
}

private void btnClose_Click(object sender, EventArgs e)
{
    _chromeProcess.CloseMainWindow();
    _chromeProcess.WaitForExit();
    _chromeProcess.Close();
}

这篇关于可能的一个过程,导致泄漏的内存也被杀害后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆