Does GC cleanup remain if you finish the process in task manager?

I think I recently read somewhere (maybe I was even on SO, but I can’t find the question) that in the debugging session, pressing stop in VS just kills the process and the GC does not take place. However, closing the application window usually performs the GC as expected.

Is it correct?

Also, what happens when a (non-debugging) process is killed in the task manager - is it still clearing the GC?

+4
source share
1 answer

If you kill the process, the operating system will clear the process memory, but there will be no GC inside the .NET runtime, and no finalizers will be executed.

Edit: (the above was correct only if you killed the process, and not when using the "Final Task")

If you send “Finish task”, it will send the corresponding WM_CLOSE message box to the program and will not end the process immediately, and .NET will be able to complete the work normally.

Edit: (one more addition)

If you stop debugging, it is roughly equivalent to TerminateProcess() , which will immediately shut down the process.

+12
source

All Articles