Rabu, 05 Januari 2011

WP7: When does GC Consider a Local Variable as Garbage

Consider the following code that I receivedstatic void Foo(){    TestClass t = new TestClass();    Listl = new List();    l.Add(t); // Last use of l and t    WeakReference w = new WeakReference(t);    GC.Collect();    GC.WaitForPendingFinalizers();    Console.WriteLine("Is Alive {0}", w.IsAlive);}If this code is is run on the desktop it prints Is Alive False. Very similar to the

Tidak ada komentar:

Posting Komentar