Why call GC.KeepAlive in the end, and not in the beginning? [duplicate]
问题 This question already has answers here : Understanding garbage collection in .NET (2 answers) Closed 7 years ago . From GC.KeepAlive() on MSDN: Code this method at the end, not the beginning, of the range of instructions where obj must be available. Why does it have such non-intuitive behavior? 回答1: Because otherwise technically the JIT and CLI could determine that the value isn't used after that point, and consider the object viable for collection. Heck, the compiler could decide to remove