Can a conforming C# compiler optimize away a local (but unused) variable if it is the only strong reference to an object?
It doesn't matter what the C# compiler does - the JITter/GC are allowed to clean up local references once they're no longer alive in a method body. Look at the docs for GC.KeepAlive
Also, this powerpoint presentation, especially from slide 30 onwards, helps to explain what the JIT/GC can get up to.
While my question has been answered, I thought I'd post this relevant piece of information I just found on the MSDN blog article "WP7: When does GC Consider a Local Variable as Garbage" by abhinaba:
[T]he ECMA specification (ECMA 334 Section 10.9) […] states
“For instance, if a local variable that is in scope is the only existing reference to an object, but that local variable is never referred to in any possible continuation of execution from the current execution point in the procedure, an implementation might (but is not required to) treat the object as no longer in use.”
This says it all. The mentioned article also says that the .NET framework (at least in Release mode) will perform predictive analysis and free such objects, while the .NET Compact Framework won't (for performance reasons).