Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the GC still clean up if you end process in task manager?

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?

like image 479
PaulB Avatar asked Dec 17 '22 08:12

PaulB


1 Answers

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.

like image 144
Martin C. Avatar answered Jan 19 '23 00:01

Martin C.