如果您在任务管理器中结束进程,GC是否仍然清理?(Does the GC still clean up if you end process in task manager?)

编程入门 行业动态 更新时间:2024-10-11 09:19:16
如果您在任务管理器中结束进程,GC是否仍然清理?(Does the GC still clean up if you end process in task manager?)

我想我最近在某处读过(甚至可能是在SO上,但我找不到问题),在调试会话中,按下VS中的停止只会杀死进程并且不会发生GC。 但是,关闭应用程序窗口通常会按预期执行GC。

它是否正确?

另外,在任务管理器中(非调试)进程被终止时会发生什么 - GC是否仍然清除?

I think I read somewhere recently (might even have been on SO but I can't find the question) that in a debug session, pressing stop in VS just kills the process and no GC takes place. However closing the app window normally performs GC as expected.

Is this correct?

Also, what happens when a (non-debug) process is killed in task manager - does the GC still cleanup?

最满意答案

如果您终止进程,操作系统将清理进程的内存,但.NET运行时内部不会发生GC,也不会运行终结器。

编辑:(只有当你杀死进程时,上述才是正确的,而不是如果你使用“结束任务”)

如果您发送“结束任务”,那么它会向程序发送适当的WM_CLOSE窗口消息,并且不会立即终止进程,.NET可以正常关闭。

编辑:(另一个附录)

如果停止调试,则对TerminateProcess()大致等同, TerminateProcess()将立即关闭该进程。

If you kill the process, the operating system will clean up the memory of the process, but no GC inside the .NET runtime will occure and no finalizers will run.

Edit: (the above was correct only if you kill the process, not if you use "End Task")

If you send "End Task", then it will send the appropriate WM_CLOSE window message to the program and will not terminate the process at once and .NET can shut down properly.

Edit: (yet another addendum)

If you stop debugging, it is roughly equivilent to TerminateProcess(), which will shut down the process at once.

更多推荐

本文发布于:2023-07-27 08:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1287668.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:您在   任务管理器   进程   结束   GC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!