views:

173

answers:

1

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?

+12  A: 

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.

Martin C.