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.
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:
- 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.
- Kill()
- 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.
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();
}