Take the C# code
static void Main(string[] args)
{
new object();
}
this is the generated IL
.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
// Code size 7 (0x7)
.maxstack 1
IL_0000: newobj instance void [mscorlib]System.Object::.ctor()
IL_0005: pop
IL_0006: ret
} // end of method App::Main
The point being that it simply calls the newobj opcode and doe not store a reference to the object anywhere. Therefore the object is immediately garbage (I don't mean that it gets collected I mean that it has no live root). This object will get collected as soon as the GC runs, even if it is at the next line of code. In addition it will not be marked as GC'able - nothing ever is. The fact that something is able to be GC'd is discovered by the GC at the point it runs, not before.
Regards
Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
Hi,
That object is immediate garbage unless it is being used as a parameter.
If it is a parameter ...
I don't believe this is the case, in any case it would be marked as GC
able, so the next time the GC runs it will be collected.
I haven't see the code generated for that line ( nor that I would know how
to interprete it either

) , but what I expect it to do is that it create
an anonymous variable, assign it and then set it to null, then it will be
collected as usual by the GC
This would be the easier to implement escenario I believe.