Java garbage collection mechanism
<p>When we write like this:
    {
    new A().test();
    }
The memory of A will be collected by gc after this function return(I knew that it's possible for collection, not be collected right now). The question is, how does the jvm make sure the memory of A won't be realise during the test() excuting(I assume the gc is a independent thread). I thought the compiler may change the statement into this:</p>

<pre><code>{
    //cover it in a scope
    {
    A temp = new A();
    temp.test();
    }
    //outside the scope, temp is no longer stay in stack, so that A's memory can be colllected
}
</code></pre>

<p>This is just a conjecture.
BTW, very sorry for my poor English, please use simple syntax(to answer or explain), thanks.     </p>
