C# - An objects scope
<p>I have looked at <a href="http://www.yoda.arachsys.com/csharp/parameters.html">this</a> and <a href="http://www.yoda.arachsys.com/csharp/memory.html">this</a> and I have the following question to see if I understand correctly.
Given the code </p>

<pre><code>using System;

namespace returnObject
{
    class myObject
    {
        public int number { get; set; }

    }

    class Program
    {
        static void Main(string[] args)
        {

            myObject mainObj = make();
            mainObj.number = 7;
        }

        public static myObject make()
        {
            myObject localObj = new myObject();
            localObj.number = 4;
            return localObj;
        }

    }
}
</code></pre>

<p>I would expect <code>localObj</code> to go out of scope at the end of the make method and, therefore, the setting of <code>obj.number</code> to 7 in the main function to fail. It doesn't. 
I think I am correct in stating that:</p>

<ul>
<li><code>localObj</code> is a reference to an object</li>
<li><code>localObj</code> is created on the stack </li>
<li><code>localObj</code> goes out of scope at the end of the make method. </li>
<li>the object that <code>localObj</code> refers to is on the heap. </li>
</ul>

<p>So, am I right in thinking that ordinarily the object that <code>localObj</code> refers to would have been marked for deletion by the garbage collector at the end of the make method but since the reference value has been passed back to <code>mainObj</code>, the object is referenced and therefore not eligible for deletion?</p>

<p>In addition is object creation in this way considered good practice?</p>
