On Mar 26, 4:07*am, "Peter Morris"
<peter[dot]morris(at)capableobjects.comwrote:
I believe not, take this example
object x = new Person();
x.FirstName = "Peter";
x.LastName = "Morris";
//Position A
..lots of code here..
//Position B
x.FullName = x.FirstName + " " + x.LastName;
//Position C
..lots of code here..
The first thing to remember is that the GC can interrupt this method at any
point. *If it interrupts at position A it will not collect the value in "x"
because the value is referenced later in the method. *If it interupts at
position C it will be able to collect the value in "x" because it is no
longer used.
In summary
The object is only held onto in this example if the variable is referenced..
The fact that the object is referenced by a variable is irrelevant if that
variable is not itself referenced.
Pete
Strangley, it can be collected in position B halfway through the call
to FullName as long as it's after any explicit or implicit use of the
'this' pointer inside that property.
Here is a link that explains why this might be important to you and
gives a example of where you would use GC.KeepAlive.
http://blogs.msdn.com/cbrumme/archiv.../19/51365.aspx