When Instance #1 is instantiatied, the first thing that happens is the
fields are initialized. The first field (GoodStone) creates another
instance of Tire, call that Instance #2.
Instance #2 starts to intialize its fields. The first field,
GoodStone, creates another instance of Tire, call that Instance #3.
Instance #3 starts to initialize its fields. The first field,
Goodstone, creates another instance of Tire, call that Instance #4.
And so on, until all memory is exhausted. All of this occurs in one
thread of execution, so no instance of Tire ever gets past the
initialization of the GoodStone field.
If you set a breakpoint on the initialization of the second field you
should see that it never gets executed.
On Sat, 29 Nov 2008 05:43:21 GMT, "pedestrian via DotNetMonster.com"
<u16758@xxxxxx> wrote:
>Why is the instantiation of a Tire and subsequent Tire instantiation
>didn't call the constructor? I never see the Console.WriteLine text being
>showed...
>
>I appreciate your explanation.
>
>Jack Jackson wrote:
>>The first instantiation of a Tire attempts to create a new Tire for
>>GoodStone. The creation of that Tire attempts to create a new Tire
>>for its Goodstone. The creation of that Tire attempts to create a new
>>Tire for its Goodstone.
>>
>>You can see where this is going. It never gets past initializing
>>Goodstone in any instance.
>>>>[quoted text clipped - 11 lines]
>>>Yes, fields are initialized first...
>>>
>>>>Fields are initialized before the constructor code executes. That causes
>>>>the recursion with no output.


