Assuming a function that takes a list of objects:
void WriteData(List<LargeObject> objectsToWrite);
If we are calling this function, for readability or debugging we might consider making this a local variable:
var objectsToWrite = SomeMethodThatPreparesTheObjects();
WriteData(objectsToWrite);
However, we might also inline the variable such that the functional call becomes:
WriteData(SomeMethodThatPreparesTheObjects());
The two are functionally equivalent - but my question is: Do both methods keep the list of objects around until the end of the method execution (because there is a local variable which would be a GC root) - or does it depend on compiler internals as to whether the latter call ends up being translated into a local variable?