Does garbage collection run during debug?

前端 未结 2 1594
-上瘾入骨i
-上瘾入骨i 2020-11-29 10:49

I have a program that opens an Excel COM object, does some stuff, and closes it. Then I want to move that file after it\'s closed. This works fine if I run the program witho

2条回答
  •  猫巷女王i
    2020-11-29 11:00

    Garbage collection is optimized differently when running not in the debugger, yes. In particular, the CLR can detect that a variable won't be used for the rest of a method, and treat it as not a GC root any more. In the debugger, variables in scope act as GC roots throughout the method so that you can still examine the values with the debugger.

    However, that should rarely be a problem - it should only affect things if a finalizer actually performs some clean-up, and if you're explicitly tidying things up in a timely way (e.g. with using statements) you usually wouldn't notice the difference.

提交回复
热议问题