That you pass a reference to a static method does in no way imply that the object will be rooted in any way, so that alone is not enough to prevent it from being collected.
Whether or not it can be collected during the method call, or only after it has completed, depends on what the method does with the argument, and whether the object is in use outside of the method call.
For instance, consider this hypothetical code:
public static class Program()
{
public static void Main()
{
SomeObject o = new SomeObject();
OtherMethod(o);
}
private static void OtherMethod(SomeObject x)
{
// lots of code here, but none that uses x
}
}
in this case, o can be collected during the call to OtherMethod
, provided you compile and run a release build. For release builds, variables and parameters that are no longer in use, that is, there is no code that uses it, are considered dead, and thus no longer counted when checking if there are live references to the object.
In Debug build, all variables and parameters are artificially kept alive until methods return, so that you can set a breakpoint and inspect the variable, even though there is no code left that uses it.
So if you were to run the above code from a debug build, then the object would be kept alive until Main returned.