We know from the C# specification that reference read/writes are atomic. In a statement that accesses member of an object, will the reference also be accessed atomically? I think yes because it is also a kind of implicit reference read which the compiler must provide atomicity for while generating code for it.
In the same statement, accessing the object to access its member will this cause the objects reference held so it is not garbage collected when a new instance is created by another thread?
So, if we access members in a chain, will the leftmost objects reference is also be held so it is not garbage collected by other threads?
Consider the following code;
static SomeClass sharedVar;
void someMethod()
{
SomeClass someLocalVar = sharedVar.memberX.memberY.a;
operations on someLocalVar...
}
I am looking for official explanation about the subject, from MSDN library, C# specs, etc. or Microsoft people to make sure that I am not breaking something and everything is fine.