How does c# remove the memory allocated in loop?
<p>imagine this code:</p>

<pre><code>int i=9999999;
while ( i &gt; 1 )
{
    string UnusedMemory="this is a string that eats some ram" + i.ToString();
    i--;
}
</code></pre>

<p>if unreferenced objects were removed only sometimes when <code>GC.Collect()</code> is run, this code should allocate lot of ram until collect happen. But it doesn't allocate huge memory at all, why? Is there some kind of "delete" implemented on IL level? Or is <code>GC.Collect()</code> called automatically faster? I know this is a trivial example, but if it was more complicated and string was accessed in that block of code, it wouldn't eat lot of ram anyway.</p>

<p>EDIT: I changed the example so that string is always unique, so that it can't be "cached"</p>
